我有一個UISearchbar,它的鍵盤上的返回鍵呈灰色,除非我在搜索欄中輸入文本。我如何讓它不出現在文字上?如果這不可能,如果搜索欄中沒有文字,我該如何返回到我的視圖?在UISearchbar中沒有文本返回
繼承人一些代碼:
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
touchtoCancel = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-211)];
[touchtoCancel addTarget:self
action:@selector(DidPressCancelSearch:)
forControlEvents:UIControlEventTouchUpInside];
[self.search setFrame:CGRectMake(self.search.frame.origin.x, self.search.frame.origin.y-210,
self.search.frame.size.width, self.search.frame.size.height)];
return YES;
}
-(IBAction)DidPressCancelSearch:(id)sender
{
[search resignFirstResponder];
}
您可以使用帶搜索欄的內置取消按鈕。 – user1673099