UISearchBar 在 UTableViewHeader 中无法正确显示
以编程方式添加了 uisearch bar 和 uisearchbardisplaycontoller (NO XIB),搜索栏显示在表标题中,但不起作用。
如果在显示控制器上设置Active:YES,setActive:NO,它看起来很好并且功能正常
您知道为什么会发生这种情况吗?
提前致谢
searchBar = [[UISearchBar alloc] init];
[self setSearchBarDisplayController:[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self]];
[[self searchBarDisplayController] setDelegate:self];
[[self searchBarDisplayController] setSearchResultsDataSource:self];
summaryTableView = [[[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 416.0) style:UITableViewStylePlain] autorelease];
[summaryTableView setDataSource:self];
[summaryTableView setDelegate:self];
[summaryTableView setBackgroundColor:[UIColor clearColor]];
[summaryTableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
[summaryTableView setRowHeight:[PayCell height]];
[summaryTableView setTableHeaderView:searchBar];
[self.view addSubview:summaryTableView];
[searchBarDisplayController setActive:YES];
[searchBarDisplayController setActive:NO];
Added a uisearch bar and uisearchbardisplaycontoller programatically (NO XIB) and the search bar sorta displays in the table header but is non functional.
if setActive:YES, setActive:NO on the display controller it appears just fine and is functional
Any ideas why this might be happening?
THanks in advance
searchBar = [[UISearchBar alloc] init];
[self setSearchBarDisplayController:[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self]];
[[self searchBarDisplayController] setDelegate:self];
[[self searchBarDisplayController] setSearchResultsDataSource:self];
summaryTableView = [[[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 416.0) style:UITableViewStylePlain] autorelease];
[summaryTableView setDataSource:self];
[summaryTableView setDelegate:self];
[summaryTableView setBackgroundColor:[UIColor clearColor]];
[summaryTableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
[summaryTableView setRowHeight:[PayCell height]];
[summaryTableView setTableHeaderView:searchBar];
[self.view addSubview:summaryTableView];
[searchBarDisplayController setActive:YES];
[searchBarDisplayController setActive:NO];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
难道是你没有为搜索显示控制器设置searchResultsDelegate?
在开发者网站上参考是做到了这一点。如果没有看到更多代码,很难说,但不设置它可能是问题的根源。这是摘录:
Could it be that you haven't set up the searchResultsDelegate for the search display controller?
On the Developer Site reference is made to this. Without seeing more code, it's hard to say, but not setting it could be the root of your problem. Here's an excerpt: