当行在iOS上是不同的一天时,如何简单地插入日期标题?
我有一个UITableView,在这里我使用nib文件向一行添加数据。我只是在表中显示,如果用户点击该行,什么也不会发生,它只是一个报告 但是,我有很多行,有些行发生在同一天,我想添加一个细行来对这些行进行分组 我可以在CellForRowatineXpath中执行此操作吗 以下是我当前的代码:当行在iOS上是不同的一天时,如何简单地插入日期标题?,ios,uitableview,Ios,Uitableview,我有一个UITableView,在这里我使用nib文件向一行添加数据。我只是在表中显示,如果用户点击该行,什么也不会发生,它只是一个报告 但是,我有很多行,有些行发生在同一天,我想添加一个细行来对这些行进行分组 我可以在CellForRowatineXpath中执行此操作吗 以下是我当前的代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)ind
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ReportCell";
ReportCell *cell = (ReportCell *) [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle]
loadNibNamed:@"ReportCell"
owner:nil options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]]) {
cell = ((ReportCell *) currentObject);
break;
}
}
}
最好的方法可能是使用节 看看
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
UITableView支持带有标题的节 此问题/答案讨论如何使用由核心数据支持的分区表视图: