在UINavigationbar中添加完成按钮 [英] Add a done button in a UINavigationbar
本文介绍了在UINavigationbar中添加完成按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户触摸特定的文本字段或文本视图时,如何向UINavigationbar添加完成按钮?
How does one add a done button to a UINavigationbar when the user touches a specific textfield or textview?
或者更好的方法是检测何时显示键盘,然后显示按钮.
Or would a better way be to detect when the keyboard is showing, and then display the button.
我希望完成按钮能够像标准Notes应用程序一样关闭键盘.
I would like the done button to dismiss the keyboard like in standard Notes application.
推荐答案
您可以尝试类似的操作:
You could try something similar to this:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(doneEditing)];
[[self navigationItem] setRightBarButtonItem:doneButton];
[doneButton release];
}
还有
- (void)textViewDidBeginEditing:(UITextView *)textView
{
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(doneEditing)];
[[self navigationItem] setRightBarButtonItem:doneButton];
[doneButton release];
}
根据您的喜好定制以下内容
with the following customized as you like
- (void)doneEditing {
[[self view] endEditing:YES];
}
然后在-(void)textFieldDidEndEditing:(UITextField *)textField
中以及在-(void)textViewDidEndEditing:(UITextView *)textView
只记得设置代表!
这篇关于在UINavigationbar中添加完成按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文