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 禁用滑动删除,但在编辑模式下仍有删除?
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
