我有UISearchBar
。我希望键盘在用户点击搜索后立即消失...我确实尝试了resignFirstResponder
但是没有用。任何帮助将不胜感激
- (void)viewDidLoad {
[super viewDidLoad];
self.title = NSLocalizedString(@"Songs", @"Search for songs");
NSMutableArray *array = [[NSArray alloc]initWithObjects: @"Book_1", @"Book 2", @"Book _ 4", nil];
self.booksArray = array;
[array release];
search.delegate=self;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
感谢 TC
答案 0 :(得分:0)
它应该通过在委托对象上实现响应方法来实现:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
}
答案 1 :(得分:0)
请确保以下事项。(我希望您在谈论键盘的搜索按钮。)
IBOutlet
searchBar与其变量search
相关联。- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
方法与searchBar所在的viewcontroller
相同。searchBarSearchButtonClicked
中验证两个实例是否相同,然后在代码中的某处重新分配search
。[searchBar resignFirstResponder];
NSLog之后(@“isFirstResponder:%d”,[searchbar isFirstResponder]);和NSLog(@"Next Responder : %@",[searchBar nextResponder]);
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
当您点击键盘的搜索按钮时,正在调用方法?确保responder
后面添加的键盘textField
(如textView
,searchBar
或其他searchBar
)可能是无意中添加的。请通过xib检查。谢谢,