美文网首页 ios零碎记录
iOS基础--UITableView分组列表

iOS基础--UITableView分组列表

作者: 暴走的羊驼 | 来源:发表于2016-11-10 17:33 被阅读798次
Grouped Style

让 Cell与Cell之间存在间距,今天来说说用UITableViewStyleGrouped实现。
先来看效果图

效果图效果图

1.属性设置


2.按组来分,每组一行

代码块

#pragma mark - 数据源方法
#pragma mark 返回分组数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{  
       return _addressData.count;
}
#pragma mark 返回每组行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{   
       return 1;
}

注意:一定要设成每组一行,才能达到分组的效果。


3.取值时,取Section

//取组的数据
AddressModel*model=_addressData[indexPath.section];

4.第一行头部分隔较大问题

//将Table Header设为10
self.tableView.tableHeaderView= [[UIViewalloc]initWithFrame:CGRectMake(0.0f,0.0f,HScreenWidth,10.f)];

提示:关于删除cell问题,采用局部刷新方式,按组来分和按行来分删除cell问题有所区别

按组来分 删除cell:
[weakSelf.tableViewdeleteSections:[NSIndexSetindexSetWithIndex:indexPath.section]withRowAnimation:UITableViewRowAnimationFade];
按行来分 删除cell:
[weakSelf.tableViewdeleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationFade];
大家伙可以试着做做...
我是暴走的羊驼,想弄懂很多,最后选择脚踏实地

相关文章

网友评论

    本文标题:iOS基础--UITableView分组列表

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