UISearchview 响应操作 - TableSearch 示例 iphone
我想修改tableSearch示例代码,使tableview没有笔尖。由于它已经是 tableviewcontroller 子类,我可以这样调用 tableview:
MainViewController *mainViewController = [[MainViewController alloc] initWithStyle:UITableViewStylePlain];//NibName:@"MainView" bundle:nil];
没有笔尖,我想手动添加搜索栏。我在下面尝试过:
UISearchBar* searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,10, 320, 41)];
[searchBar setFrame:CGRectMake(0,10, 320, 41)];
searchBar.delegate = self;
searchBar.tintColor = [UIColor redColor];
[searchBar sizeToFit];
self.tableView.tableHeaderView = searchBar;
搜索栏确实显示正常。现在我希望此搜索栏的搜索操作指向我的代码中已有的方法,即 searchDisplayController 委托方法。 无论如何,我可以将 self.searchDisplayController 的搜索栏属性指向我的自定义搜索栏,以便它们执行相同的操作吗?提前致谢...
I would like to modify the tableSearch sample code, so that there is no nib for the tableview. As it is already a tableviewcontroller subclass, I can call the tableview like this:
MainViewController *mainViewController = [[MainViewController alloc] initWithStyle:UITableViewStylePlain];//NibName:@"MainView" bundle:nil];
Without the nib, I would like to add the search bar manually. I tried below:
UISearchBar* searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,10, 320, 41)];
[searchBar setFrame:CGRectMake(0,10, 320, 41)];
searchBar.delegate = self;
searchBar.tintColor = [UIColor redColor];
[searchBar sizeToFit];
self.tableView.tableHeaderView = searchBar;
The searchbar does appear ok. Now I would like the search action of this searchbar to point to the methods that I already have in my code, i.e searchDisplayController delegate methods.
Is there anyway I can point the self.searchDisplayController's Search bar property to my custom searchbar, so they do the same actions? Thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须使用
UISearchDisplayController
的initWithSearchBar:contentsViewController
方法。这样,您的自定义搜索栏将与控制器关联。您还必须在此方法中设置contentsViewController
。You have to use the
initWithSearchBar:contentsViewController
method ofUISearchDisplayController
. This way, your custom search bar will be associated with the controller. Also you have to set thecontentsViewController
in this method.hm ..这是我的VC之一的代码。还设置Uisearchbardelegate,UisearchDisplayDelegate
,然后
Hm.. this is code from one of my VC. Also set UISearchBarDelegate,UISearchDisplayDelegate
And then