UISearchDisplayController 自动创建一个 UIPopovercontroller 来显示内容搜索结果?!如何驳回它?

发布于 2024-09-08 07:29:23 字数 789 浏览 9 评论 0 原文

我将 UISearchDisplayController 与 UISearchBar 一起使用。我使用 IB 将这个 UISearchBar 放入我的应用程序中,得到:

alt text http://img6.imageshack.us/img6 /1985/screenshot20100701at156.png

很好:当你开始点击时,结果 popovercontroller 神奇地出现(我自己没有写任何东西让它出现!)

然后,当在结果中单击一行时,我想要在这个阶段关闭 PopoverController 但是,我从未实例化过我这边的 UIPopoverController :看起来 UISearchDisplayController 中是否有一个封装的行为,会自动包装其 UIPopoverController 内的 >searchContentsController。这真的很棒,因为一切都可以完美运行,无需执行任何操作,除了我无法获取对此 UIPopoverController 的引用来关闭它:(

有谁知道如何获取对这个“神奇”创建的 UIPopoverController 的引用? (这证明了 iPad 确实是一个“神奇”设备;)

我认为会从其 contentController 中引用 UIPopoverController (例如通过其父属性),但我找不到任何方法来获取指向它的指针:/

I'm using a UISearchDisplayController with a UISearchBar. I put this UISearchBar in my app using IB and I get :

alt text http://img6.imageshack.us/img6/1985/screenshot20100701at156.png

Fine : when you start taping, the result popovercontroller appears magically (I didn't write anything on my own to make it appear !)

Then, when a row is clicked among the result, I want to dismiss the PopoverController BUT at this stage, I never instantiated the UIPopoverController on my side : it looks like if there's an encapsulated behavior in the UISearchDisplayController that automatically wraps its searchContentsController inside a UIPopoverController. That's really great because everything works perfectly without doing anything except that I cannot get the reference to this UIPopoverController to dismiss it :(

Does anyone know how to get the reference to this "magically" created UIPopoverController ?
(this is the proof the iPad is really a "magical" device ;)

I thought there would be a reference to the UIPopoverController from its contentController (through its parent property for instance), but I cannot find any way to get a pointer to it :/

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

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

发布评论

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

评论(3

趁年轻赶紧闹 2024-09-15 07:29:23

那么 [searchDisplayController setActive:NOanimated:YES]; 不起作用吗?

Does [searchDisplayController setActive:NO animated:YES]; not work then?

时光瘦了 2024-09-15 07:29:23

上述解决方案都不适合我,但我用这个解决了它:

    [self.searchDisplayController setActive:NO animated:YES];
    [searchBar becomeFirstResponder];

这样光标停留在字段中,但当没有结果时弹出窗口被关闭。

完整代码:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    if ([searchText isEqualToString:@""]) {
        [self.searchDisplayController setActive:NO animated:YES];
        [searchBar becomeFirstResponder];
    }
}

None of above solutions worked for me, but I solved it with this:

    [self.searchDisplayController setActive:NO animated:YES];
    [searchBar becomeFirstResponder];

This way cursor stays in the field but popover is dismissed when there are no results.

Full code:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    if ([searchText isEqualToString:@""]) {
        [self.searchDisplayController setActive:NO animated:YES];
        [searchBar becomeFirstResponder];
    }
}
你怎么敢 2024-09-15 07:29:23

您能否添加一些有关如何在 IB 中连接 UISearchDisplayController 的更多详细信息?它对 iPad 上的 UIPopoverControllers 没有做任何特殊的事情,所以我假设您已将 searchContentsController 设置为 UIPopoverController 的控制器?如果是这样,那么您已经拥有了所需的参考,尽管通常您不需要关闭此视图,但当您取消搜索时,它会为您关闭。

Can you add some more details on how you have wired up the UISearchDisplayController in IB? It does not do anything special with UIPopoverControllers on the iPad so I assume you have set the searchContentsController to a controller that is a UIPopoverController? If so then you already have the reference you need, though normally you do not need to dismiss this view, it is dismissed for you when you cancel the search.

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