becomeFirstResponder无法调起键盘

今天发现一个问题,落在具体代码上是一个UITextView的子类在调用becomeFirstResponder函数后,键盘没有呼出来。

首先检查了该子类的相关函数,比如:

- (BOOL)canBecomeFirstResponder
{

之类的,都是return YES,但当调用时:
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];
}

发现这里super会先becomeFirstResponder抢占了。。。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值