I create a grouped style tableview
and the table has 5 sections ,and each section has different numbers of rows
Here is my code
1.Set how many sections in a table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 5;
}
2.Set each rows in a section
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
switch (section) {
case 0:
return 1;
break;
case 1:
return 2;
break;
case 2:
return 3;
break;
case 3:
return 1;
break;
case 4:
return 2;
break;
default:
return 1;
}
}
3.Give a section header :
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case 0:
return @"Section 1";
break;
case 1:
return @"Section 2";
break;
case 2:
return @"Section 3";
break;
case 3:
return @"Section 4";
break;
case 4:
return @"Section 5";
break;
default:
return nil;
}
}
5.Only give first row in first section data(because others I'm not have idea to set the cell yet)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if (indexPath.section==0 && indexPath.row==0) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = @"About System";
}
return cell;
}
than I got two same Cell in Section 0 Row0,and Section 4 Row 0
But If I mark the section header
It only appear a text label at Section 0 Row 0
IS my switch logic error ? or just compiler issue ????