我有一个预先填入“当前位置”的UISearch栏,但是当用户开始输入时,我想删除预填充文本并仅显示用户正在键入的文本。我试过这个,但似乎无法让它工作:
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
if ([self.searchBar.text isEqualToString:CURRENT_LOCATION]) {
self.searchBar.text=@"";
}
}
答案 0 :(得分:1)
Use Folowing
- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text NS_AVAILABLE_IOS(3_0);