原理大致如下,
对editingStyleForRowAtIndexPath 对相应的cell进行相应的属性设置
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
CourseModel *model = _dataArray[indexPath.section];
if (model.nLockStatus != 0)
return UITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert;
else
return UITableViewCellEditingStyleNone;
}通过此处后,可以发现有些cell在编辑下已经没有了相应的样式,但此时还有一个问题,当处于编辑时,cell的最左侧始终有一块白的区域。。。。如下图,
解决以上问题原理如下,当tableview处于编辑时,其下的cell会调用layoutSubviews重新进行界面布局,所以我们只需要在这里面进行相应处理即可,所以我们通过重写UITableViewCell子类的layoutSubviews即可实现上述需求
XXXUITableViewCell.m-(void)layoutSubviews
{
[super layoutSubviews];
if (_model.nLockStatus == 0)
{
CGRect frame = self.contentView.frame;
frame.origin.x = 0;
self.contentView.frame = frame;
}
}最终实现效果如下
本文介绍如何在UITableView中根据数据模型动态调整UITableViewCell的编辑样式,并解决了编辑模式下单元格左侧空白的问题。
1万+

被折叠的 条评论
为什么被折叠?



