使用“后退"按钮展开搜索功能 [英] Unwind segue function with Back button

查看:38
本文介绍了使用“后退"按钮展开搜索功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我按导航控制器中的默认后退"按钮(例如<设置)时,我正在尝试调用函数.

I'm trying to call function when i'm pressing default Back button (e.g. < Settings) in Navigation Controller.

在其他情况下,我在Ctrl + X拖动到XCode中的红色退出"按钮并将其指向选择"序列后,将创建自定义按钮.

现在我需要使用导航控制器的默认后退按钮,但是由于在Storyboard视图中没有后退按钮(但它存在于Simulator中),所以我无法将其分配给segue动作.

Now i need to use default back button of navigation controller, but i can't set assign it to segue action because it's no back button in Storyboard view (but it exists in Simulator).

模拟器:

XCode:

我可以在导航控制器中创建自定义按钮,并对其进行分配,以便进行自定义展开,但是该按钮在没有<"符号的情况下会很丑陋.

I can create custom button in navigation contoller and assign it so custom unwind segue, but that button will be ugly without "< " symbol.

我在stackoverflow上找到了一些答案,但是它们都是用Objective-C编写的:(.

I've found some answers at stackoverflow, but they all are written in Objective-C :(.

推荐答案

您可以使用委托方法来完成您的工作.

You can use a delegate method to accomplish what you are doing.

这是一个经过深思熟虑的快速教程,它处理了代表和问题: http://makeapppie.com/2014/07/05/using-delegates-and-segues-part-2-the-pizza-demo-app/

Here is a really thought out swift tutorial that deal with delegates and segues: http://makeapppie.com/2014/07/05/using-delegates-and-segues-part-2-the-pizza-demo-app/

您要问的是捕捉后退按钮动作的能力,这并不是您描述的方式.

What you are asking, ability to catch the back button's action, isn't possible the way you describe it.

大多数人会建议创建一个自定义按钮,然后使用放松按钮.

Most people would recommend creating a custom button, then use an unwind segue.

有许多关于自定义后退按钮的教程,以防万一您不熟悉它,并且可以通过在其中放置自己的箭头来轻松地修复自定义后退按钮的丑陋部分.

There are lots of tutorials on custom back buttons just in case you're new to swift, and the ugly part of the custom back button can be easily fixed by putting your own arrow there.

我也找到了之前问过的问题,以备将来参考:解开segue通过Swift中的导航后退按钮

Also I found this previous asked question for future reference: Unwind segue from navigation back button in Swift

这篇关于使用“后退"按钮展开搜索功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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