Ваши разделы tableViews будут последовательно пронумерованы, начиная с 0. Если у вас нет PM-рассказов, то AM-публикации будут разделом 0, а передовые статьи - разделом 1. Если у вас действительно есть хранилища PM, то AM-публикации будут разделом 0Истории PM будут разделом 1, а редакционные статьи - разделом 2.
Вы можете вернуть правильное количество разделов из numberOfSectionsInTableView:
в зависимости от того, пуст ли ваш массив PM Stories:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if ([pmStoresArray count] > 0) {
return 3;
} else {
return 2;
}
}
Затем в cellForRowAtIndexPath:
вы можете использовать ту же логику, чтобы определить, к какой категории раздела относится ячейка:
- (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];
}
if (indexPath.section == 0) {
// am stories cell
} else if (indexPath.section == 1 && [pmStoriesArray count] > 0) {
// pm stories cell
} else {
// editorials cell
}
return cell;
}