
让 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];
网友评论