我想自定义我的单元格行为 - 我希望更改单元格 View 并显示不同的按钮。我成功了一半 - 当我滑动时, View 就会移动。
但是我在单元格的右侧有一个删除按钮,我想删除它并使用自定义按钮代替它。我应该使用什么来删除它以及在哪里绑定(bind)我的按钮来执行相同的操作?
我尝试使用两种方法,setEditing
: 和 willTransitionToState
,但这没有帮助。
如果我在其中任何一个中跳过调用父方法,我就不会得到我想要的删除按钮,但我的 View 在编辑后永远不会返回到其原始位置,并且其他单元格停止对滑动使用react。我需要做什么来解决这个问题?
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:YES];
if (editing) {
[UIView animateWithDuration:0.3 animations:^{
self.parentView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 100, 0);
}];
} else {
[UIView animateWithDuration:0.3 animations:^{
self.parentView.transform = CGAffineTransformIdentity;
}];
}
}
-(void)willTransitionToState:(UITableViewCellStateMask)state
{
[super willTransitionToState:state];
if (state == UITableViewCellStateShowingDeleteConfirmationMask) {
[UIView animateWithDuration:0.3 animations:^{
self.parentView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 100, 0);
}];
}
if (state == UITableViewCellStateDefaultMask) {
[UIView animateWithDuration:0.3 animations:^{
self.parentView.transform = CGAffineTransformIdentity;
}];
}
}
最佳答案
由于您的单元格是 UITableViewCell 的子类,并且您不想使用库存删除,因此您可能需要禁用它。最基本的方法是不返回任何单元格的编辑样式。
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}
一些评论提到了您下一步可以做什么。
- 在单元格主视图下方添加一个附加 View 。
- 在该 View 右侧与删除按钮相同的位置添加一个按钮。
- 使用滑动手势识别器进行基本滑动或使用平移手势识别器
用于拖动(正常行为)。 - 根据翻译更新顶 View 框架。
关于ios - 如何在编辑UITableViewCell时删除删除按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21821731/