Если вы уже знаете даты, которые хотите использовать для разделов, сохраните их в массиве как массивы.Другими словами, создайте массив для каждой даты, которую вы хотите использовать в качестве раздела.Затем просмотрите ваши customObjects и вставьте их в соответствующий массив разделов.Если у вас есть этот метод, используйте numberOfSectionsInTableView
, чтобы получить количество секций.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [datesArray count];
}
Тогда вам нужно будет указать UITableDelegate, сколько строк вам понадобится на секцию.Для этого вы используете numberOfRowsInSection
.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[datesArray objectAtIndex:section] count];
}
Затем в методе cellForRowAtIndexPath
просто получите данные customObject для ячейки из соответствующего массива раздела.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CustomTableCell";
static NSString *CellNib = @"UserCustomTableCell";
UserCustomTableCell *cell = (UserCustomTableCell *)[table dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil];
cell = (UserCustomTableCell *)[nib objectAtIndex:0];
}
MyObject *customObject = [[datesArray objectAtIndex:indexPath.section] indexPath.row];
//Setup your cell here
cell.date.text = [customObject date];
return cell;
}