UITableView disable swipe to delete, but still have delete in Edit mode?(UITableView 禁用滑动删除,但在编辑模式下仍有删除?)
问题描述
我想要类似闹钟应用的东西,你不能滑动删除行,但你仍然可以在编辑模式下删除行.
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.
当注释掉 tableView:commitEditingStyle:forRowAtIndexPath: 时,我禁用了滑动删除并且在编辑模式下仍然有删除按钮,但是当我按下删除按钮时会发生什么.叫什么?
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;
}
斯威夫特 2
override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
if tableView.editing {
return .Delete
}
return .None
}
斯威夫特 3
override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
if tableView.isEditing {
return .delete
}
return .none
}
你仍然需要实现 tableView:commitEditingStyle:forRowAtIndexPath:
来提交删除.
You still need to implement tableView:commitEditingStyle:forRowAtIndexPath:
to commit the deletion.
这篇关于UITableView 禁用滑动删除,但在编辑模式下仍有删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UITableView 禁用滑动删除,但在编辑模式下仍有删除?


基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01