我将 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 :/
发布评论
评论(3)
那么
[searchDisplayController setActive:NOanimated:YES];
不起作用吗?Does
[searchDisplayController setActive:NO animated:YES];
not work then?上述解决方案都不适合我,但我用这个解决了它:
这样光标停留在字段中,但当没有结果时弹出窗口被关闭。
完整代码:
None of above solutions worked for me, but I solved it with this:
This way cursor stays in the field but popover is dismissed when there are no results.
Full code:
您能否添加一些有关如何在 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.