今天发现一个问题,落在具体代码上是一个UITextView的子类在调用becomeFirstResponder函数后,键盘没有呼出来。
首先检查了该子类的相关函数,比如:
- (BOOL)canBecomeFirstResponder {
BOOL bRet = [_inputTextView becomeFirstResponder];却是return NO。
参考这个回答,考虑了两点:
是否在主线程——是;
是否有其它firstResponder拒绝resign——通过这个方法寻找当前firstResponder为nil。
参考文档说明:
- (BOOL)becomeFirstResponder
Description Notifies the receiver that it is about to become first responder in its window.
Subclasses can override this method to update state or perform some action such as highlighting the selection. A responder object only becomes the first responder if the current responder can resign first-responder status (canResignFirstResponder) and the new responder can become first responder.
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.
Returns YES if the receiver accepts first-responder status or NO if it refuses this status. The default implementation returns YES, accepting first responder status.
Availability iOS (2.0 and later) Declared In UIResponder.h Reference UIResponder Class Reference再次检查了函数的重载:
- (BOOL)becomeFirstResponder { [super becomeFirstResponder]; return [internalTextView becomeFirstResponder]; }