开发者

iPhone App - Hide picker show keyboard and hide keyboard show picker

in the iPhone app, i have both the text field and picker in the same window. I want the picker popup to disappear when user clicks on textfield and keyboard appears. Similarly keyboard should disappear and picker popup should come up when use开发者_开发知识库r clicks on picker. Any sample code?


You have to use textfielddidbeginEditing method. In which you can if condition for identifying textfield and on the basis of that return yes if you want to show keyboard and return no if you dont want to display keyboard. Here if you return no than keyboard will not display same time you can show your picker with your custom code.

Hope this will help you.


There is also a way to listen for system notifications for the keyboard appearing.

In your controller, do this:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

Then, just implement the method keyboardWillShow:(id)sender, and you'll have everything you need.

There's another notification for when the keyboard disappears, too.

If you then need to hide the keyboard, you need to call "resignFirstResponder" on whatever object that particular keyboard is associated with.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜