你如何解散 UISearchController ?(iOS 8 及后续版本) [英] How do you dismiss a UISearchController ? (iOS 8 and follow)

查看:22
本文介绍了你如何解散 UISearchController ?(iOS 8 及后续版本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一定是微不足道的,但我找不到您应该如何以编程方式关闭 UISearchController?

This must be trivial, but I can't find how you're supposed to dismiss a UISearchController programmatically?

请注意,这是新的 UISearchController(于 2014 年随 iOS 8 引入),而不是 UISearchDisplayController.

Note that it's the new UISearchController (introduced in 2014 with iOS 8), not the UISearchDisplayController.

到目前为止,这是我所拥有的

So far here's what I've got

// Dismiss the search tableview
searchController.dismissViewControllerAnimated()
// Clear the Search bar text
searchController.active = false

但我仍然有取消按钮,无法摆脱它.

But I still have the cancel button and can't get rid of it.

推荐答案

OK 所以经过更多的测试,结果你只需要设置:

OK so after more testing, turns out you just have to set:

searchController.active = false
// or swift 4+
searchController.isActive = false

这是我尝试的第一件事,但我在其中一个无效的 UISearchControllerDelegate 方法中调用了它(可能应该使用 dispatch_async 调用它(halbano 的回答似乎证实了这一点)).

This is the first thing I tried but I called it in one of the UISearchControllerDelegate methods which didn't work (probably should have called it with dispatch_async (halbano's answer seems to confirm that)).

总之,由于我在网上找不到那个答案,我正在回答我自己的问题,希望对某人有所帮助.

Anyway, since I couldn't find that answer online, I'm answering my own question, I hope that it'll help someone.

这篇关于你如何解散 UISearchController ?(iOS 8 及后续版本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆