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

查看:120
本文介绍了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天全站免登陆