我在我的应用程序中使用了UISearchDisplayController。当用户选择返回的搜索结果中的项目时,我会停用UISearchDisplayController。停用控制器会清除用户输入的文本。我想保留它。在控制器被停用后,我尝试通过再次设置它来将文本赋回到UISearchBar中。文本确实出现在搜索栏中,但这会导致UISearchDisplayController重新激活,即使我已经禁用了代理!这个问题只发生在iOS 7上。在iOS 7之前,下面的代码运行得很好。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSUInteger row = [indexPath row];
NSString *term = [keywordSuggestion objectAtIndex:row];
[search resignFirstResponder];
[self handleSearchForTerm:term];
}
-(void)handleSearchForTerm:(NSString *)searchTerm {
[searchDisplayController setActive:NO animated:YES]; //searchbar text will be lost
searchDisplayController.delegate = nil;
search.text = term;
searchDisplayController.delegate = self;
}
有没有一种方法可以设置UISearchBar的文本,而不必使与之关联的UISearchDisplayController变为活动状态?