ios - becomeFirstResponder 在 cellForRowAtIndexPath 中不起作用

标签 ios uitableview uitextview

当从 cellForRowAtIndexPath 调用 textView becomeFirstResponder 时返回 false,为什么?

但是从其他方法,即从 didSelectRowAtIndexPath 可以工作。

是否与我使用 iOS 8 引入的 UITableViewAutomaticDimension 行高方法有关?!

最佳答案

当您查看文档时,它说 View 必须位于 View 层次结构中。我认为在 cellForRowAtIndexPath 方法中, TextView 尚未附加到层次结构,而是在返回单元格时。

You may call this method to make a responder object such as a view the first responder. However, you should only call it on that view if it is part of a view hierarchy. If the view’s window property holds a UIWindow object, it has been installed in a view hierarchy; if it returns nil, the view is detached from any hierarchy.

关于ios - becomeFirstResponder 在 cellForRowAtIndexPath 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32526673/

相关文章:

objective-c - 不在绘制时更新 UITableViewDelegate

ios - Swift - 使用按钮手动滚动 UITextView

ios - 使用带有搜索栏的键搜索 Firebase 数据库

iphone - 将字符串转换为 NSDate 对象

ios - 应用程序退出 *** 断言失败 -[UITableView _configureCellForDisplay :forIndexPath:]

ios - 从 Firebase 查询创建 TableView (iOS、Swift)

ios - 总是预防性地将 UI 更改包装到主线程中?

ios - 具有自定义宽度的 UISearchBar 在 UINavigationBar 向上滑动动画期间消失

ios - Swift 中 UITextView 和 UITextField 的单一扩展

ios - 使 UITextView 在 UIStackView 中工作