UITableView reloadData 自动调用 resignFirstResponder [英] UITableView reloadData automatically calls resignFirstResponder

查看:40
本文介绍了UITableView reloadData 自动调用 resignFirstResponder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个带有自定义单元格的 UITableView,它只能获取预定义的值,因此我使用 UIPickerView 作为它们的 inputView.在我编辑一个字段并需要显示其更新值之前,一切都很好.

I have this UITableView with custom cells that can get only predefined values, therefore I use a UIPickerView as their inputView. All is jolly good until I edit a field and need to show its updated value.

为了让事情更清晰、更易于维护,我将委托和数据源作为单独的类,并使用通知使它们与 tableView 交互.因此,在从 UIPickerView 中选择一个值后,tableView 的数据源会收到通知,然后通知主 ViewController 持有对 tableView 的引用.从那里我打电话

In order to make things clearer and easier to maintain, I made delegates and data sources as separate classes, and use notifications to make them interact with the tableView. So, after a value has been chosen from the UIPickerView, the tableView's data source gets notified, and in turn notifies the main ViewController that holds a reference to the tableView. From there I call

[_tableView reloadData];

一切似乎都有效,除了 UIPickerView 消失了,我想是因为单元格重新生成并且在某个地方调用了 resignFirstResponder 或类似的东西.有没有其他方法可以让 tableView 更新其值,而不必在某处实现自定义方法,这会很丑陋?

and everything seems to work, except that the UIPickerView disappears, I think because the cells are regenerated and somewhere some resignFirstResponder is called, or something like that. Is there any other way to make the tableView updating its values without having to implement a custom method somewhere that does it, which would be quite ugly?

推荐答案

这读起来像预期的行为 - 选择器属于特定单元格,该单元格被重新加载并且不再是第一响应者.我无论如何都必须选择一个特定的元素才能出现选择器,即使其成为第一响应者.

This reads like expected behavior - the picker belongs to a particular cell, that cell gets reloaded and is not the first responder any more. I guess one had to select a specific element anyway for the picker to appear, i.e. to make it first responder.

所以你要么重新加载后让它再次成为第一响应者,要么直接更新特定的单元格.

So you either need to make it become first responder again after reloading, or update the specific cell directly.

这篇关于UITableView reloadData 自动调用 resignFirstResponder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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