【发布时间】:2010-03-04 10:12:30
【问题描述】:
问题的简短描述: 我想设置搜索栏的文本,而不自动触发绑定到它的搜索显示控制器。
问题的详细描述: 我有一个带有搜索栏和搜索显示控制器的 iphone 应用程序。 searchdisplay 控制器用于自动完成。对于自动完成,我使用 sqlite 数据库。用户输入关键字的前几个字母,结果显示在搜索显示控制器的表格中。为每个键入的字符执行一个 sql 选择查询。这部分工作正常,字母已输入,结果可见。
问题如下:如果用户从表中选择一行,我想将搜索栏的文本更改为在自动完成结果表中选择的文本。我还想隐藏搜索显示控制器。这是行不通的。搜索显示控制器消失后,搜索栏中的文本框为空。我不知道出了什么问题。我没想到像更改文本框的文本这么简单的事情会变得如此复杂。
我尝试用 2 种方法更改文本: 首先在 didSelectRowAtIndexPath 方法中(用于搜索显示控制器的搜索结果表),但这没有帮助。当搜索显示控制器处于活动状态(动画消失)时,文本就在那里,但之后文本框为空。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"didSelectRowAtIndexPath");
if (allKeywords.count > 0)
{
didSelectKeyword = TRUE;
self.selectedKeyword = (NSString *)[allKeywords objectAtIndex: indexPath.row];
NSLog(@"keyword didselectrow at idxp: %@", self.selectedKeyword);
shouldReloadResults = FALSE;
[[self.mainViewController keywordSearchBar] setText: selectedKeyword];
//shouldReloadResults = TRUE;
[[mainViewController searchDisplayController] setActive:NO animated: YES];
}
}
我也尝试在 searchDisplayControllerDidEndSearch 方法中更改它,但这也无济于事。文本框......再次......为空。
编辑:实际上文本不是空的,但在动画消失后,自动完成表的结果仍然存在。所以它最终会变得更糟。
- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
{
NSLog(@"searchDisplayControllerDidEndSearch");
if (didSelectKeyword)
{
shouldReloadResults = FALSE;
NSLog(@"keyword sdc didendsearch: %@", selectedKeyword);
[[mainViewController keywordSearchBar] setText: selectedKeyword]; //
在这个方法中,我调用了另一个从 sqlite 中选择数据的方法。这部分工作正常。
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { NSLog(@"shouldReloadResults : %i", shouldReloadResults); 如果(应该重新加载结果) { NSLog(@"shouldReloadTableForSearchString: %@", searchString); [self GetKeywords: searchString:@"GB"]; NSLog(@"shouldReloadTableForSearchString vege"); 返回是; } 返回否; }如果不清楚我的问题是什么,请询问我。我需要你的帮助。谢谢
【问题讨论】:
标签: iphone objective-c uisearchdisplaycontroller searchdisplaycontroller