美文网首页
iOS开发实用小技巧:集成tableview的sectionIn

iOS开发实用小技巧:集成tableview的sectionIn

作者: 小熊的故事啊 | 来源:发表于2017-10-18 20:50 被阅读0次

新项目需要做一个类似通讯录的东西,需要首字母索引的sectionIndex,集成也非常简单
第一个方法是table表右边的首字母的array

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
    return self.array;
}

第二个方法是点击右边的字母时,跳转到对应的section,其中参数index是指点击的字母所在数组的index

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
    return index;
}

只用这两句就会发现tableview整个右边会有空白列,UI非常不美观,所以又找到了解决的办法。
其实只要加上这两句话就可以完美解决tableview的sectionIndex遮挡了headerView和searchBar的问题。

  self.tableView.sectionIndexBackgroundColor=[UIColor clearColor]; self.tableView.sectionIndexTrackingBackgroundColor = [UIColor clearColor];

相关文章

网友评论

      本文标题:iOS开发实用小技巧:集成tableview的sectionIn

      本文链接:https://www.haomeiwen.com/subject/rnaeuxtx.html