【发布时间】:2013-06-09 22:49:49
【问题描述】:
我正在尝试在表格的标题视图中创建一个带有搜索栏的表格视图。我想使用 searchDisplayController 来管理所有内容。 我以编程方式创建了所有内容(我对 IB 感到不舒服)试图设置所有正确的属性,但似乎我遗漏了一些东西,因为当表格出现时我无法编辑文本搜索栏并查看任何动画。 以下是部分代码:
- (void)viewDidLoad {
[super viewDidLoad];
UISearchBar *searchBarTMP=[[UISearchBar alloc]init];
self.searchBar=searchBarTMP;
[searchBarTMP release];
self.searchBar.autocapitalizationType=UITextAutocapitalizationTypeNone;
self.searchBar.delegate=self;
self.searchBar.showsScopeBar=YES;
self.searchBar.keyboardType=UIKeyboardTypeDefault;
self.searchBar.userInteractionEnabled=YES;
self.searchBar.multipleTouchEnabled=YES;
self.searchBar.scopeButtonTitles=[NSArray arrayWithObjects:NSLocalizedString(@"City",@"Scope City"),NSLocalizedString(@"Postal Code",@"Scope PostalCode"),nil];
self.tableView.tableHeaderView=searchBar;
self.searchBar.selectedScopeButtonIndex=0;
self.navigationItem.title=NSLocalizedString(@"Store",@"Table title");
//SearchDisplayController creation
UISearchDisplayController *searchDisplayControllerTMP = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
self.searchDisplayController=searchDisplayControllerTMP;
[searchDisplayControllerTMP release];
self.searchDisplayController.delegate=self;
self.searchDisplayController.searchResultsDelegate=self;
self.searchDisplayController.searchResultsDataSource=self;
//....continue
}
我知道当您单独使用搜索栏时,您必须处理它的委托协议,但我猜测 searchDisplayController 会为您管理,如 Apple 示例代码中所示。 (通过 IB 建立)。
有什么建议吗? 谢谢, 安德烈亚
【问题讨论】:
标签: iphone uisearchbar edit uisearchdisplaycontroller