В этом случае вы можете использовать пользовательскую ячейку заголовка, а затем эту ячейку присоединить в заголовке.
для этого следующего кода реализуется.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 5;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 2;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *v=[[[NSBundle mainBundle] loadNibNamed:@"tHeader" owner:self options:nil] objectAtIndex:0];
[(UILabel*)[v viewWithTag:1] setText:[NSString stringWithFormat:@"%i",section+1]];
return v;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return (section==0)?5:((section==1)?7:((section==2)?3:4));
}
// Customize the appearance of table view cells.
- (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];
}
cell.textLabel.text=[NSString stringWithFormat:@" Hello-%i",indexPath.row];
// Configure the cell.
return cell;
}
Скачать исходный код здесь.