0

searchBar :shouldChangeTextInRange:replacementText从未调用过。定义了委托,方法 - searchBarShouldBeginEditing:searchBarTextDidBeginEditing : 工作正常, 但未调用shouldChangeTextInRange。我发现当在使用alertview的方法中设置时,并且在我尝试使用搜索栏之后..调用 shouldChangeTextInRange ......但之前没有

-(void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
     }

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
 return YES;
}

-(BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
 return YES;
}


-(BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
return  YES;
 }

 -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

  }
4

1 回答 1

0

我错过了 appDelegate ,applicationDidFinishLauching下面的代码

 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];

现在 SearchBar 工作正常!

于 2013-01-04T17:35:36.307 回答