【发布时间】:2014-06-04 22:30:30
【问题描述】:
我在我的应用程序中使用 UISearchDisplayController。当用户在返回的搜索结果中选择一个项目时,我会停用 UISearchDisplayController。停用控制器会清除用户键入的文本。我想把它留在那里。我尝试在控制器停用后通过再次设置将文本分配回 UISearchBar。文本确实出现在搜索栏中,但这将导致 UISearchDisplayController 再次激活,即使我禁用了委托!这个问题只发生在 iOS 7 上。在 iOS7 之前,下面的代码运行得很好。
- (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?
【问题讨论】:
标签: ios ios7 uisearchbar uisearchdisplaycontroller