=> I know this is a stupid question, but it is more important for a new iPhone developer like me.
here I have a question related to the UITableView section :
First problem: I have a question: how can I start a UITableView section with number 0 from several sections?
Example:
I have 11 sections in a UITableView and in the delegate method numberOfSectionsInTableView , my section starts with the 11th number of sections, then 0,1,2,3,4,5,6,7,8, 9 and 10. since I can run the partition number with the number 0, and then as it is.
second problem: in the titleForHeaderInSection delegate method, all sections of the View table are repeated 3 times. and with the current ViewController i, scrolling UITableView up or down, then the section displays as normal (0 to 11) this normal section of the UITableView display after repeating the section 3 times.
Example:
I am using NSLog (@" %d ", section ); in the titleForHeaderInSection delegate method, and then print to the console as shown below
Console:
2012-09-17 12:27:47.424 Quotes2You[1623:f803] 11 2012-09-17 12:27:47.426 Quotes2You[1623:f803] 11 2012-09-17 12:27:47.427 Quotes2You[1623:f803] 11 2012-09-17 12:27:47.428 Quotes2You[1623:f803] 0 2012-09-17 12:27:47.429 Quotes2You[1623:f803] 0 2012-09-17 12:27:47.429 Quotes2You[1623:f803] 0 2012-09-17 12:27:47.430 Quotes2You[1623:f803] 1 2012-09-17 12:27:47.431 Quotes2You[1623:f803] 1 2012-09-17 12:27:47.431 Quotes2You[1623:f803] 1 2012-09-17 12:27:47.432 Quotes2You[1623:f803] 2 2012-09-17 12:27:47.433 Quotes2You[1623:f803] 2 2012-09-17 12:27:47.433 Quotes2You[1623:f803] 2 2012-09-17 12:27:47.434 Quotes2You[1623:f803] 3 2012-09-17 12:27:47.435 Quotes2You[1623:f803] 3 2012-09-17 12:27:47.436 Quotes2You[1623:f803] 3 2012-09-17 12:27:47.436 Quotes2You[1623:f803] 4 2012-09-17 12:27:47.437 Quotes2You[1623:f803] 4 2012-09-17 12:27:47.438 Quotes2You[1623:f803] 4 2012-09-17 12:27:47.438 Quotes2You[1623:f803] 5 2012-09-17 12:27:47.439 Quotes2You[1623:f803] 5 2012-09-17 12:27:47.439 Quotes2You[1623:f803] 5 2012-09-17 12:27:47.440 Quotes2You[1623:f803] 6 2012-09-17 12:27:47.441 Quotes2You[1623:f803] 6 2012-09-17 12:27:47.462 Quotes2You[1623:f803] 6 2012-09-17 12:27:47.463 Quotes2You[1623:f803] 7 2012-09-17 12:27:47.464 Quotes2You[1623:f803] 7 2012-09-17 12:27:47.465 Quotes2You[1623:f803] 7 2012-09-17 12:27:47.466 Quotes2You[1623:f803] 8 2012-09-17 12:27:47.466 Quotes2You[1623:f803] 8 2012-09-17 12:27:47.467 Quotes2You[1623:f803] 8 2012-09-17 12:27:47.472 Quotes2You[1623:f803] 9 2012-09-17 12:27:47.476 Quotes2You[1623:f803] 9 2012-09-17 12:27:47.478 Quotes2You[1623:f803] 9 2012-09-17 12:27:47.480 Quotes2You[1623:f803] 10 2012-09-17 12:27:47.481 Quotes2You[1623:f803] 10 2012-09-17 12:27:47.481 Quotes2You[1623:f803] 10 2012-09-17 12:27:47.487 Quotes2You[1623:f803] 0 2012-09-17 12:27:47.487 Quotes2You[1623:f803] 1 2012-09-17 12:27:47.489 Quotes2You[1623:f803] 2
first repeat all sections 3 times and after I scroll through a UITableView, then the start starts at 0 (as usual)
My code is here:
ThirdViewController.h
@interface ThirdViewController : UIViewController<UITableViewDataSource, UITableViewDelegate> { UITableView *tblCustomer; NSArray *listOfsection; } @property (nonatomic,retain) UITableView *tblCustomer; @property (nonatomic,retain) NSArray *listOfsection; @end
ThirdViewController.m
@synthesize tblCustomer , listOfsection; - (void)viewDidLoad { [super viewDidLoad]; self.tblCustomer = [[UITableView alloc] initWithFrame:CGRectMake(0,0,320,417) style:UITableViewStyleGrouped]; self.tblCustomer.delegate = self; self.tblCustomer.dataSource = self; [self.view addSubview:self.tblCustomer]; self.listOfsection = [[NSArray alloc] initWithObjects:@"Name", @"Company", @"Address", @"Email", @"Mobile", @"Phone", @"Potential", @"Sales Status", @"Genre", @"Distributor", @"Dist Rep", @"Internal Notes", nil]; } #pragma mark - UITableView Datasource Methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView { return [self.listOfsection count]; } - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section { int numSection=0; if (section == 2) numSection = 5; else numSection = 1; return numSection; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // here is my code cellForRowAtIndexPath as section wise } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSLog(@" %d ", section); NSString *sectionHeader = nil; sectionHeader = [self.listOfsection objectAtIndex:section]; // here is section overwrite // return sectionHeader; } #pragma mark - Memory Management -(void)dealloc { [super dealloc]; [self.listOfsection release]; [self.tblCustomer release]; }
Thank you in advance