- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我的 UITableView 有一组单元格。滑动单元格会导致出现删除按钮。点击这个 Remove 按钮会导致执行以下代码:
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
[self.itemList removeObjectAtIndex:indexPath.row];
这正确地导致单元格从列表中删除。但是,当我点击 UITableVIew 中剩余的单元格之一以选择它时,此点击将被忽略(即未调用 tableView:didSelectRowAtIndexPath)。如果我第二次点击,它就会正常工作(即调用 tableView:didSelectRowAtIndexPath)。
无论删除后点击哪个单元格,删除后等待多长时间,删除后第一次点击总是被忽略,删除成功后第二次点击。
根据各种 stackOverflow 答案,我尝试过:
self.tableView.editing = NO;
[self.tableView reloadData];
[self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
[self.tableView beginUpdates];
,在删除后调用[self.tableView endUpdates];
以上都没有帮助;删除后的第一次点击仍然始终被忽略。
更新:我还在上面的代码片段中添加了 [self.itemList removeObjectAtIndex:indexPath.row];
代码。我的数据源委托(delegate)方法如下所示:
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.itemList.count;
}
上面的代码片段在 doDelete 方法中被调用以响应按钮点击 ([self.deleteButton addTarget:self action:@selector(doDelete) forControlEvents:UIControlEventTouchUpInside];
)
更新 #2:根据 Lyssa 的评论,我尝试了以下操作:我删除了对自定义删除按钮和滑动手势的所有引用,然后将此代码添加到我们的 UITableView 委托(delegate)中:
-(BOOL) tableView:(UITableView*)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
-(void) tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.itemList removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
}
这确实有效 - 我现在可以删除行,下一次点击也能正常工作。但是,这会删除我们对表格单元格的自定义外观,这首先是我们自定义代码的目的。也许我应该考虑使用上述方法并改为自定义“删除”按钮(我已经做了一些研究,但还没有找到好的答案)。
最佳答案
问题是,当您使用滑动删除时,只有您滑动的行会进入编辑模式。
第一次点击是结束该行的编辑模式:
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath {
}
可以通过设置编辑模式来解决
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.itemList removeObjectAtIndex:indexPath.row];
[self.tableView setEditing:NO animated:YES];
}
[self.tableView reloadData];
}
关于ios - deleteRowsAtIndexPaths 后忽略 UITableView 的第一次点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20497349/
当我从表中删除行时,我的应用程序崩溃了。这是我检测到错误和堆栈跟踪的来源。谢谢! //delete row from database - (void)tableView:(UITableView *
我对 Swift 和 iOS 比较陌生,我有一个问题 - 我有一个扩展 UITableViewCell 的自定义 SwipeCell 类。这是一个可以左右滑动的单元格,每侧都有按钮。出于某种原因,如果
关于这个问题有几个问题。我已经尝试了所有建议的答案,但还没有任何效果。所以我有这个 func用户收到的拒绝报价。我可以拒绝报价并删除单元格行,但是当只剩下一个单元格时,我得到 fatal error:
我正在尝试借助 deleteRowsAtIndexPaths 折叠和展开 UITableView 部分。似乎什么都没有发生,但我不明白为什么。 NSMutableArray *tmpArray
我正在尝试使用以下代码删除。 [super deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade
尝试成为 ios7 风格,我在点击表格中的单元格时将 UIPickerView 插入到 UITableView 中。这工作正常并且动画效果很好。但是,当我通过调用 deleteRowsAtIndexP
这个问题在这里已经有了答案: crash on deleteRowsAtIndexPaths (5 个答案) 关闭 7 年前。 我试图在稳定 View 中删除一行,但每次我在应用程序中选择删除时它都
我在IB中设计了UIView,并在其上设计了UITableView。在 View Controller 的 viewDidLoad 方法中,我初始化自定义 UITableViewContoller 并
当我尝试将 deleteRowsAtIndexPaths 与动画 UITableViewRowAnimationTop 一起使用时,我要删除的单元格覆盖了上面的单元格(在动画中),然后消失。我做了一个
当我尝试将 deleteRowsAtIndexPaths 与动画 UITableViewRowAnimationTop 一起使用时,我要删除的单元格覆盖了上面的单元格(在动画中),然后消失。我做了一个
我目前有一个包含多个部分的表格 View 。每个部分包含特定日期的数据。每个部分都有一个标题,说明数据是在多少天前输入的。 当使用deleteRowsAtIndexPath删除行时,当该部分中的所有行
我正在尝试很好地删除 mu UITableView 的单元格: - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITab
我不太确定这里发生了什么,但我遇到了一个我正在使用的联系表。在我的表单中,我添加了向联系人添加电子邮件地址的功能。如下图所示,一旦用户点击“添加电子邮件”,一行就会添加到“电子邮件”部分。 但是,在我
这个问题在这里已经有了答案: crash on deleteRowsAtIndexPaths (5 个答案) 关闭 7 年前。 当我从 tableView 中删除一行时发生崩溃。不确定发生了什么。这
我有一个 UITableView 和一个在后台运行的调度程序,从底层数据对象中删除记录。每次删除对象时,我都希望 TableView 相应地更新。 但是当我尝试从 TableView 中删除一行时,我
我想知道是否有可能捕捉到在 deleteRowsAtIndexPaths 期间触发的动画是否结束?我想要做的是从 UITableView 中删除一些所有行,除了我点击的行。接下来我想在同一个 UITa
我在 Swift、iOS 8、Xcode 6 Beta 6 中从我的 tableView 中删除一行时遇到了一些麻烦。每次我尝试删除一行时,我都会收到类似 的错误 Assertion failure
我有一个可能有几百行的表格,所有行的高度都不同。每当用户删除一行时,调用: [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnim
我有一个动态的 TableView,想用动画删除行。 我的代码: struct TableItem { let text: String let id: String let
我正在尝试从 deleteRowsAtIndexPaths 更新我的 tableView 以使用 animation.fade 。所以请你告诉我如何在我有两个数组时更新 tableView? func
我是一名优秀的程序员,十分优秀!