ios - 当 iOS 上的行不同时,如何简单地插入日期标题?

标签 ios uitableview

我有一个 UITableView,我在其中使用 nib 文件将数据添加到一行。我刚刚展示了表格,如果用户点击该行,什么都不会发生,它只是一个报告。

但是,我有很多行,有些行出现在同一日期,我想添加一个细行来对这些行进行分组。

如果不能,我可以在 cellForRowAtIndexpath 中执行此操作吗?

这是我当前的代码:

- (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

关于ios - 当 iOS 上的行不同时,如何简单地插入日期标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4097757/

相关文章:

ios - XMPPFramework-TURNSocket无法接收到我自己发送的数据吗?

ios - 如何在 Swift 3 中解码 html 格式的文本

javascript - 使用 jquery : does not work on Iphone, safary 等显示和隐藏微调器

ios - 将字符串从 TableView Controller 传递到新 View Controller

objective-c - 如何实现 "Refresh"和 "Reload"表(代码重构)

ios - 创建水平滚动菜单

ios - 使用循环运行后台获取时出现 NSInternalInconsistencyException

ios - 具有分页功能的动态表格 View

ios - UITableViewCell EditingStyle Delete自动取消选择tableview中的所有可见单元格

ios - 选择单元格时如何更改蓝色突出显示颜色