UISearchview 响应操作 - TableSearch 示例 iphone

发布于 2024-12-04 08:41:03 字数 746 浏览 2 评论 0原文

我想修改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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

£冰雨忧蓝° 2024-12-11 08:41:03

您必须使用 UISearchDisplayControllerinitWithSearchBar:contentsViewController 方法。这样,您的自定义搜索栏将与控制器关联。您还必须在此方法中设置 contentsViewController

You have to use the initWithSearchBar:contentsViewController method of UISearchDisplayController. This way, your custom search bar will be associated with the controller. Also you have to set the contentsViewController in this method.

初心未许 2024-12-11 08:41:03

hm ..这是我的VC之一的代码。还设置Uisearchbardelegate,UisearchDisplayDelegate

_listContainer = [[UITableView alloc] init];
_listContainer.delegate = self;
_listContainer.dataSource = self;
_listContainer.separatorStyle = UITableViewCellSelectionStyleNone;
_data = [[NSArray alloc] init];

,然后

_searchBar = [[NL_CustomSearchBar alloc] initWithFrame:CGRectMake(4.0f, 0, 150, 46)];
 _searchBar.delegate = self;
 _listContainer.tableHeaderView = _searchBar;

Hm.. this is code from one of my VC. Also set UISearchBarDelegate,UISearchDisplayDelegate

_listContainer = [[UITableView alloc] init];
_listContainer.delegate = self;
_listContainer.dataSource = self;
_listContainer.separatorStyle = UITableViewCellSelectionStyleNone;
_data = [[NSArray alloc] init];

And then

_searchBar = [[NL_CustomSearchBar alloc] initWithFrame:CGRectMake(4.0f, 0, 150, 46)];
 _searchBar.delegate = self;
 _listContainer.tableHeaderView = _searchBar;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文