以编程方式执行放松搜索 [英] Perform unwind segue programmatically

查看:91
本文介绍了以编程方式执行放松搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我有以下故事板:

UITableViewController-> Segue-> UINavigationController-> Relationship-> UITableViewController

在上一个UITableViewController中,我添加了一个带有以下代码的后退按钮:

navigationItem.setLeftBarButtonItem(UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "unwind"), animated: true)

let attributes = [NSFontAttributeName: UIFont.fontAwesomeOfSize(30), NSForegroundColorAttributeName: Constants.InterfaceColors.firstHighlightColor] as Dictionary!
let unwindNavigationItem = navigationItem.leftBarButtonItem! as UIBarButtonItem

unwindNavigationItem.setTitleTextAttributes(attributes, forState: .Normal)
unwindNavigationItem.title = String.fontAwesomeIconWithName(FontAwesome.AngleLeft)

据我所读,我必须将文件的所有者连接到情节提要中的出口.我发现,只有在您的控制器代码中有以下操作时,这才可能实现.

@IBAction func unwindToWeekOverview(segue: UIStoryboardSegue) {
        NSLog("unwind to week overview")
        dismissViewControllerAnimated(true, completion: nil)
    }

由于我现在不怎么将按钮的动作直接与我的展开动作联系在一起,因此我添加了unwind函数.

func unwind() {
        performSegueWithIdentifier("UnwindToWeekOverview", sender: self)
    }

当我现在单击后退"按钮时,将调用展开功能,但不会调用segue. 我想念什么?

解决方案

看看此链接.这是迈克·沃默(MIKE WOELMER)的作品,他解释得很清楚.

https://spin.atomicobject.com/2014/10/25/ios-unwind-segues/

因此,首先,您需要在目标视图控制器中创建一个IBAction,如下所示:

@IBAction func goBack(segue: UIStoryboardSegue) {

    print("go back")

然后,您只需要将按钮的连接(控制拖动)连接到Exit outlet.在弹出窗口中,您将看到以前添加的功能,只需选择它即可使用.

Currently I have the following storyboard:

UITableViewController -> Segue -> UINavigationController -> Relationship -> UITableViewController

In the last UITableViewController I added a back button with the code below:

navigationItem.setLeftBarButtonItem(UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "unwind"), animated: true)

let attributes = [NSFontAttributeName: UIFont.fontAwesomeOfSize(30), NSForegroundColorAttributeName: Constants.InterfaceColors.firstHighlightColor] as Dictionary!
let unwindNavigationItem = navigationItem.leftBarButtonItem! as UIBarButtonItem

unwindNavigationItem.setTitleTextAttributes(attributes, forState: .Normal)
unwindNavigationItem.title = String.fontAwesomeIconWithName(FontAwesome.AngleLeft)

As far as I read I have to connect the File's owner to the exit in the storyboard. I found out, that this is only possible if you have an action in your controller code like the one below.

@IBAction func unwindToWeekOverview(segue: UIStoryboardSegue) {
        NSLog("unwind to week overview")
        dismissViewControllerAnimated(true, completion: nil)
    }

Since I don't now how to directly connect the action of a button to my unwind action I added the unwind function.

func unwind() {
        performSegueWithIdentifier("UnwindToWeekOverview", sender: self)
    }

When I now click the back button, the unwind function is called, but not the segue. What am I missing?

解决方案

Have a look at this link. It is by MIKE WOELMER and he explains it very clearly.

https://spin.atomicobject.com/2014/10/25/ios-unwind-segues/

So first of all, you need to create an IBAction in a destination view controller, something like this:

@IBAction func goBack(segue: UIStoryboardSegue) {

    print("go back")

Then you just need to connect (control drag) from your button to Exit outlet. In the pop up you will see the function added previously, just select it and it should work.

这篇关于以编程方式执行放松搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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