我可以在 UISearchDisplayController 中插入按钮吗?

发布于 2024-10-31 05:56:35 字数 90 浏览 2 评论 0原文

当用户点击搜索栏,没有输入任何文本,并且屏幕变暗(但桌面视图尚未出现)时,我想在屏幕上放置一个按钮以允许用户导航离开到一些其他功能。这可能吗?

谢谢!

When a user has tapped in a search bar, hasn't entered any text, and the screen has been darkened (but the tableview has not appeared yet), I would like to put a button on the screen to allow the user to navigate away to some other functionality. Is that possible?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

北凤男飞 2024-11-07 05:56:35

这是相当棘手的。 _dimmingView 是 searchDisplayController 私有的,它位于所有子视图之上。您可以做的是每次出现时用自定义视图覆盖它([searchString length] == 0 和 DidBeginSearch)

(tempView 的框架设置为放置在表的 tableViewHeader 上的 UISearchBar)

- (void)viewDidLoad {
    tempView = [[UIView alloc] initWith...];
    // tempView setup
    ...
}

- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
    [tempView setFrame:CGRectMake(0, self.searchDisplayController.searchBar.frame.size.height, 320, self.searchDisplayController.searchResultsTableView.frame.size.height)];
    [self.searchDisplayController.searchContentsController.view addSubview:tempView];
    ...
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    if ([searchString length] == 0) 
         [self.searchDisplayController.searchContentsController.view addSubview:tempView];
    else 
         [tempView removeFromSuperview];
    ...
}

- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller {
    if (tempView && tempView.superview) 
        [tempView removeFromSuperview];
    ...
}

注意:我尝试在 DidBeginSearch 上创建一个新实例并释放它在 DidEndSearch 上,并且仅适用于第一次调用!奇怪...

希望这有帮助

This is quite tricky. The _dimmingView is private to the searchDisplayController and it goes above all subviews. What you can do is cover it with your custom view every time it appears ([searchString length] == 0 and DidBeginSearch)

(tempView's frame is set for UISearchBar placed on table's tableViewHeader)

- (void)viewDidLoad {
    tempView = [[UIView alloc] initWith...];
    // tempView setup
    ...
}

- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
    [tempView setFrame:CGRectMake(0, self.searchDisplayController.searchBar.frame.size.height, 320, self.searchDisplayController.searchResultsTableView.frame.size.height)];
    [self.searchDisplayController.searchContentsController.view addSubview:tempView];
    ...
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    if ([searchString length] == 0) 
         [self.searchDisplayController.searchContentsController.view addSubview:tempView];
    else 
         [tempView removeFromSuperview];
    ...
}

- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller {
    if (tempView && tempView.superview) 
        [tempView removeFromSuperview];
    ...
}

Notes: I tried creating a new instance on DidBeginSearch and releasing it on DidEndSearch, and it worked only for the 1st call! Weird...

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文