UITableView禁用滑动来删除,但仍然在编辑模式下删除? [英] UITableView disable swipe to delete, but still have delete in Edit mode?
问题描述
我想要类似于闹钟应用程式,但您无法滑动删除该列,但仍可在编辑模式中删除该列。
out tableView:commitEditingStyle:forRowAtIndexPath :,我禁止滑动删除,并仍然有编辑模式下的删除按钮,但当我按删除按钮时会发生什么。
好吧,结果很简单。这是我为了解决这个问题:
Objective-C
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Detemine如果它在编辑模式
if .tableView.editing)
{
return UITableViewCellEditingStyleDelete;
}
return UITableViewCellEditingStyleNone;
}
Swift 2
override func tableView(tableView:UITableView,editingStyleForRowAtIndexPath indexPath:NSIndexPath) - > UITableViewCellEditingStyle {
if tableView.editing {
return .Delete
}
return .None
}
Swift 3
override func tableView(_ tableView:UITableView,editingStyleForRowAt indexPath:IndexPath) - > UITableViewCellEditingStyle {
if tableView.isEditing {
return .delete
}
return .none
}
您仍然需要实现
tableView:commitEditingStyle:forRowAtIndexPath:
才能提交删除。 >I want something similar as the Alarm app, where you can't swipe delete the row, but you can still delete the row in Edit mode.
When commented out tableView:commitEditingStyle:forRowAtIndexPath:, I disabled the swipe to delete and still had Delete button in Edit mode, but what happens when I press the Delete button. What gets called?
解决方案Ok, it turns out to be quite easy. This is what I did to solve this:
Objective-C
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { // Detemine if it's in editing mode if (self.tableView.editing) { return UITableViewCellEditingStyleDelete; } return UITableViewCellEditingStyleNone; }
Swift 2
override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle { if tableView.editing { return .Delete } return .None }
Swift 3
override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle { if tableView.isEditing { return .delete } return .none }
You still need to implement
tableView:commitEditingStyle:forRowAtIndexPath:
to commit the deletion.这篇关于UITableView禁用滑动来删除,但仍然在编辑模式下删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!