UiTextField and resignFirstResponder

被刻印的时光 ゝ 提交于 2019-12-03 16:15:39

Kendall is right. You need to set your viewController1 as the delegate of your text field.

In your comment above, I think you're misunderstanding the textFieldShouldReturn method. The UITextField* is passed in as a parameter to this method, so that the delegate can see which field wants to return, and decide whether to allow it to. In your case, you only have one textfield, so just resign first responder and return YES (my code is below).

Try putting a breakpoint on this textFieldShouldReturn function. Is it getting called?

- (BOOL)textFieldShouldReturn:(UITextField*)aTextField
{
    [aTextField resignFirstResponder];
    return YES;
}

Connect the delegate property of the text field to your view controller in IB (should be File's Owner for that view). Also note in the view controller header that you conform to the protocol.

Or you can just set the texfield.delegate property to self in the viewDidLoad method of the view controller.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!