我的應用程序有一個搜索欄,用於從sqlite數據庫填充的表視圖中搜索記錄。 我的問題是,當視圖打開時,「取消」按鈕沒有啓用,我也無法觸及它,就像只有一個圖像。它在那裏,但沒有采取任何行動。 當我們點擊那個搜索欄文本時,取消按鈕將被改爲「完成」,啓用它。 所以這裏是我的代碼搜索欄取消按鈕不起作用
這是我的搜索欄視圖,請參閱取消button.It未啓用
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
//[newSearchBar setShowsCancelButton:YES animated:YES];
newSearchBar.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
NSLog(@"search begin edit") ;
//searchString = searchBar.text;
//NSLog(@"print did edit searchstring : %@", searchString) ;
for(UIView *view in [searchBar subviews])
{
//shareItemId =newSearchBar.text;
if([view isKindOfClass:[NSClassFromString(@"UINavigationButton") class]]) {
[(UIBarItem *)view setTitle:@"Done"];
}
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
NSLog(@"searchBarTextDidEndEditing:");
[searchBar resignFirstResponder];
//[self dismissModalViewControllerAnimated:YES];
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
NSLog(@"searchBarSearchButtonClicked");
searchString = searchBar.text;
NSLog(@"search %@", searchBar.text);
[newSearchBar setShowsCancelButton:NO animated:YES];
[searchBar resignFirstResponder];
//[self dismissModalViewControllerAnimated:YES];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
NSLog(@" searchBarCancelButtonClicked");
[searchBar resignFirstResponder];
shareItemName =newSearchBar.text;
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
NSLog(@"searchBarShouldBeginEditing");
[newSearchBar setShowsCancelButton:YES animated:YES];
return YES;
}
這些都是我爲
代表請檢查我的代碼,並給我答案。我需要啓用「取消」按鈕,當視圖被加載,它的行動將回到以前的觀點
我需要這樣的
要不我怎麼能添加另一個取消按鈕激活取消button.so,我可以啓用that.please給我所有的細節
是方法'searchBarCancelButtonClicked'叫什麼名字? – visakh7 2011-05-09 07:41:05
@ 7KV7 - 如果按鈕被禁用,它甚至會被調用嗎?我的猜測是,當搜索文本字段不是第一響應者時,UISearchBar的行爲是禁用取消按鈕。 – 2011-05-09 08:27:02
您可以手動強制啓用它,如http://stackoverflow.com/questions/4348351/uisearchbar-disable-auto-disable-of-cancel-button/4349003#4349003中所述。 – Palimondo 2011-10-20 13:24:16