【问题标题】:Sort UItableView section by date conditional按日期条件对 UItableView 部分进行排序
【发布时间】:2011-11-09 13:07:06
【问题描述】:

将 myArray (NSMutableArray) 作为 dataSource 与事件

自定义表格部分是:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{
    customSections = [[NSMutableArray alloc] init];

    //My custom sections
    [customSections addObject:@"now"];
    [customSections addObject:@"in this day"];

    NSString *sectionText = [customSections objectAtIndex:section];
    return sectionText;   
}

做空它们的最佳做法是什么? 对于每个事件,我都有一个开始时间和结束时间

【问题讨论】:

    标签: iphone uitableview nsmutablearray ios5 tableview


    【解决方案1】:

    您应该在另一个地方的某个地方初始化并填写您的 customSections 数组(例如,当您初始化此类时)。比你必须做这样的事情:

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return [customSections count];
    }
    
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
        return [customSections objectAtIndex:section];
    }
    

    【讨论】:

    • 举个例子,也许会更清楚: myArray 它是一个带有事件的 NSMutableArray; firstSection 将只包括现在正在发生的事件,第二个可以说今天的事件......
    • 尝试了解 tableView 的工作原理。 TableView 会询问它的 dataSource 的节数(numberOfSectionsInTableView:),而不是询问 dataSource 的每个节的标题(tableView:titleForHeaderInSection:),在这种方法中,您将获得节数。根据此编号,您将为部分返回适当的标题。 tableView 还会询问 dataSource 每个部分的行数 (tableView:numberOfRowsInSection:)。最后,tableView 将向 dataSource 询问特定行特定部分中的单元格 (tableView:cellForRowAtIndexPath:)。
    • 像 Apple 的 example 但对我来说只有两个自定义部分
    • 好的。您从我的帖子和评论中不明白什么?如果您想要 2 个部分,那么您应该像我之前写的那样在 numberOfSectionsInTableView: 方法中返回 2...
    • 抱歉没说清楚;我知道如何指定 tableView 中的节数;我不确定如何在第一部分现在发生事件,在第二部分今天发生事件......
    猜你喜欢
    • 1970-01-01
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    相关资源
    最近更新 更多