python tableview绑定字典_TableView索引的添加

首先是在这个代理函数中添加索引数组:

#pragma mark-索引显示数组

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

{

NSMutableArray *array = [NSMutableArray array];

for (int i = 0; i < datasource.count; i++) {

NSDictionary *dic = datasource[i];

NSString *temp = [dic allKeys][0];

[array addObject:temp];

}

return array;

}

这样就可以在右侧显示了,说明下,我的模型数组里面嵌套字典,字典的Key为ABCD*****,字典的value为首字母为该key的用户的名字,下面是建立索引对应关系,这里的

if (key == UITableViewIndexSearch) {

[self.ContactTableView setContentOffset:CGPointZero animated:NO];

return NSNotFound;

}是不会执行的!

#pragma mark-自定义索引与数组的对应关系

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index

{

NSDictionary *dic = [datasource objectAtIndex:index];

NSString *key = [dic allKeys][0];

if (key == UITableViewIndexSearch) {

[self.ContactTableView setContentOffset:CGPointZero animated:NO];

return NSNotFound;

}

return index;

}

加上索引后,发现右侧有个白色竖条,解决方法就是设置索引的背景色为无色,代码如下:

self.ContactTableView.sectionIndexBackgroundColor = [UIColor clearColor];

方法来源于网络。。。。。有什么错误的地方,还请指正。。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值