Sko*_*ota 5 uitableview uitextfield first-responder ios
我有一个基于iOS 6的项目实现了UITableView.表视图中的每个单元格都包含UITextField允许用户输入信息的单元格.如果用户清除文本字段,或删除字段中的所有输入,(即[textfield length] == 0)当他们点击另一个单元格(文本字段)时,它会从表格视图中删除前一个单元格(文本字段),因为它是空的 - 这可以避免空单元格在表格视图中累积.
这都是使用一个为文本字段-textFieldEditingDidEnd:触发UIControlEventEditingDidEnd事件的方法完成的:
- (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];
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当代码被触发时,应用程序在控制台上崩溃并显示以下消息:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempt to delete row containing first responder that refused to resign'
我之前从未见过这个消息,在搜索网页时似乎没有特别多的引用.我将不胜感激任何有关如何解决此问题的建议.
mat*_*att 12
我以前从未见过这个消息,但是如果我看到它的话,我的直接冲动是:尝试延迟性能.即使像这样简单的事情也许是一个有趣的实验:
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
});
Run Code Online (Sandbox Code Playgroud)
我的想法是,在文本字段仍在报告时(即在textFieldEditingDidEnd仍在运行时),我们不要尝试删除该行; 让我们给runloop一个机会来完成它的循环.
| 归档时间: |
|
| 查看次数: |
3343 次 |
| 最近记录: |