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
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01