有一种基于字母表创建节索引的方法,使用UILocalizedIndexedCollation非常简单直接。 有没有办法根据12小时制创建部分索引?比如使用“HH:mm a”并将其用作节标题。
Sagos
答案 0 :(得分:3)
在数据源中实现sectionIndexTitlesForTableView:以返回标题。
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return [NSArray arrayWithObjects:@"12:00 AM", @"01:00 AM", ..., @"11:00 PM", nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 24;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch(section) {
case 0: //12:00 AM
...
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
switch(indexPath.section) {
case 0: //12:00 AM
...
}
}