解决存在间隙的问题
环信即时通讯v3.2.3版本中,通讯录的右侧会存在间隙

在Demo中找通讯录类,在 -(void)viewDidLoad
中添加如下代码:
self.tableView.sectionIndexColor = [UIColor lightGrayColor];
self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];
效果如下:

这样tableView就不会由于索引的出现存在间隙了。
但出现了另一个问题,就是搜索框会变得不对称

这个问题还未解决。
设置显示全部的索引
通讯录中搜索方法 sectionIndexTitlesForTableView
可知索引是放置在数组 self.sectionTitles
中
搜索self.sectionTitles
找到 - (void)_sortDataArray:(NSArray *)buddyList
此方法应该是设置通讯录中好友的数据
self.sectionTitles 已经添加 a-z和#
//建立索引的核心, 返回27,是a-z和#
UILocalizedIndexedCollation *indexCollation = [UILocalizedIndexedCollation currentCollation];
[self.sectionTitles addObjectsFromArray:[indexCollation sectionTitles]];
在此方法中继续读,会发现,通讯录列表中不存在的首字母索引会被移除掉

所以,新建一个数组A来保存全部索引,然后在 sectionIndexTitlesForTableView 中 返回数组A即可

- (void)_sortDataArray:(NSArray *)buddyList
中

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
中

效果如下

网友评论