[英]Move custom cells to right in UITableView in editing mode
我有一个多节UITableView
,它包含自定义单元格,由UIImage
, UILabel
等组成。当我点击导航栏上的编辑按钮时,我希望单元格内容移动到右侧。 因为我想防止“删除”视觉和我的自定义单元格的UIImage
之间的重叠。 此外,我希望它在编辑模式结束时还原。
我尝试了setIndentationLevel
但它没有用。 我该怎么办呢?
因为您使用自定义表格视图单元格,我建议您使用
override init(style: UITableViewCellStyle, reuseIdentifier: String?)
super.init(style: style, reuseIdentifier: reuseIdentifier)
如果你有一个myImageView
视图
不要添加为:
addSubview(myImageView)
而是添加为:
contentView.addSubview(myImageView)
因为contentView是一个自动向右动画的视图。
在启动期间(-viewDidLoad或在storyboard中)执行:
self.tableView.allowsMultipleSelectionDuringEditing = NO;
现在实现以下tableView委托
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Write code to change content insets of your cell here
// Return YES if you want the specified item to be editable.
return YES;
}
//覆盖以支持编辑表视图。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
// Change back the content insets of cell here
}
}
覆盖- (void)setEditing:(BOOL)editing animated:(BOOL)animated
在自定义单元格中设置- (void)setEditing:(BOOL)editing animated:(BOOL)animated
,以根据编辑值重置约束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.