尝试删除包含拒绝辞职的第一响应者的行 [英] Attempt to delete row containing first responder that refused to resign

查看:366
本文介绍了尝试删除包含拒绝辞职的第一响应者的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于iOS 6的项目,它实现了 UITableView 。表视图中的每个单元格都包含 UITextField ,允许用户输入信息。如果用户清除文本字段,或者删除字段中的所有输入(即 [textfield length] == 0 ),当他们点击另一个单元格(文本字段)时从表视图中删除前一个单元格(文本字段),因为它是空的 - 这可以避免在表视图中累积空单元格。

I have an iOS 6-based project that implements a UITableView. Each cell in the table view contains a UITextField allowing the user to enter information. If the user clears a text field, or deletes all input from the field, (i.e. [textfield length] == 0) when they tap onto another cell (text field) it deletes the previous cell (text field) from the table view, as it's empty - this avoids empty cells accumulating in the table view.

这一切都是使用一个名为 -textFieldEditingDidEnd:在文本字段的 UIControlEventEditingDidEnd 事件中触发:

This is all done using a method called -textFieldEditingDidEnd: which fires on the UIControlEventEditingDidEnd event for the text fields:

- (void)textFieldEditingDidEnd:(UITextField *)textField {

    NSIndexPath *indexPath = // Index path of the row in the table view

    if ([textField.text length] == 0) {
        // Delete the cell from the table view
        [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }

}

然而,当代码被解雇时应用程序在控制台上崩溃并显示以下消息:

However, when the code is fired the app crashes with the following message on the console:

***由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'尝试删除包含拒绝辞职的第一响应者的行

我之前从未见过这条消息,似乎没有特别多的引用在搜索网络时。我很感激有关如何解决这个问题的任何建议。

I have never seen this message before, and there do not seem to be particularly many references to it when searching the web. I would appreciate any suggestions on how to fix this issue.

推荐答案

我以前从未见过这个消息,但我的直接冲动如果我看到它会:尝试延迟表现。即使是这样简单的事情也许是一个有趣的实验:

I've never seen that message before, but my immediate impulse if I were to see it would be: try delayed performance. Even something as simple as this might be an interesting experiment:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableView deleteRowsAtIndexPaths:@[indexPath] 
     withRowAnimation:UITableViewRowAnimationAutomatic];
});

我的想法是,在文本字段仍在报告时,我们不要尝试删除该行(即 textFieldEditingDidEnd 仍然在运行);让runloop有机会完成它的循环。

My thought here is, let's not try to delete the row while the text field is still reporting in (i.e. while textFieldEditingDidEnd is still running); let's give the runloop a chance to finish its cycle.

这篇关于尝试删除包含拒绝辞职的第一响应者的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆