Добрый день!
Таблица заполняется данными с массива. В массиве есть заголовки ячейки, который должны отображаться в секции. Для каждой ячейки необходимо добавить новую секцию.
@implementation ViewController{
NSArray *tableCellTitle;
NSArray *sectionsTitle;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
tableCellTitle = [NSArray new];
tableCellTitle = @[@"Cell 1", @"Cell 2", @"Cell 3", @"Cell 4"];
sectionsTitle = [NSArray new];
sectionsTitle = @[@"Section 1", @"Section 2", @"Section 3", @"Section 4"];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [tableCellTitle count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"TableCell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [tableCellTitle objectAtIndex:indexPath.row];
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [sectionsTitle objectAtIndex:section];
}