for(NSMutableArray*sectionArrayinsectionArrays){
NSArray*sortedSection=[theCollationsortedArrayFromArray:sectionArraycollationStringSelector:@selector(getFirstName)];
[listContentaddObject:sortedSection];
}
至此为止,我们就已经将tableView的数据源进行了分组,确定了每个对象所在的section,以及每个section下得所有对象的排序,这个功能可以很方便的对tableView的数据进行排序,可以作为一个单独的功能来使用。我不实现
-(NSString*)tableView:(UITableView*)tableViewtitleForHeaderInSection:(NSInteger)section;
-(NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView
-(NSInteger)tableView:(UITableView*)tableViewsectionForSectionIndexTitle:(NSString*)titleatIndex:(NSInteger)index
这个三个代理方法就不会显示section和section index,但是我显示的数据就全是排好序的。很方便的
当然如果你想显示section和section index,就需要实现上面的这个三个方法,这三个方法可以直接用UILocalizedIndexedCollation来实现,如下:
-(NSString*)tableView:(UITableView*)tableViewtitleForHeaderInSection:(NSInteger)section
{
return[[[UILocalizedIndexedCollationcurrentCollation]sectionTitles]objectAtIndex:section];
}
-(NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView
{
return[[UILocalizedIndexedCollationcurrentCollation]sectionIndexTitles];
}
//返回sectionindex对应的section
-(NSInteger)tableView:(UITableView*)tableViewsectionForSectionIndexTitle:(NSString*)titleatIndex:(NSInteger)index
{
return[[UILocalizedIndexedCollationcurrentCollation]sectionForSectionIndexTitleAtIndex:index];
}
note:section title 和section index title 是可以不相同的。
这是我第一次写这种文章,肯定有很多说得不太得当的地方,请多谅解,多谢多谢。
以下是getFirstName的具体内容,我觉得比较实用。brmh
#import"AddressBookEntity.h"
@implementationAddressBookEntity
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/ruanjian/article-46524-2.html
我在上海
打路过的还不如先干掉霸占的
和我家过的