becomeFirstResponder not working in iOS 8

前端 未结 8 797
不知归路
不知归路 2020-12-09 03:55

I am using UITextField\'s method becomeFirstResponder to show the keyboard. This is working in iOS 7. But in iOS 8 this method doesn\'t show the keyboard.

 U         


        
8条回答
  •  被撕碎了的回忆
    2020-12-09 04:18

    Try calling becomeFirstResponder like below

    [txtAddNew performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0];
    

    As per Apple,

    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.

提交回复
热议问题