您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页iOS基础--UITableView分组列表

iOS基础--UITableView分组列表

来源:二三娱乐
Grouped Style

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

效果图

1.属性设置

  • 设置按组来分
    ![分组属性默认是Plain我们选择Grouped](屏幕快照 2016-11-09 16.40.27.png)
  • 设置每行头部间距 底部间距
    ![头部间距 底部间距](屏幕快照 2016-11-09 16.40.16.png)

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];
大家伙可以试着做做...
我是暴走的羊驼,想弄懂很多,最后选择脚踏实地

Copyright © 2019- yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务