在展开segue后执行push segue [英] Perform push segue after an unwind segue

查看:121
本文介绍了在展开segue后执行push segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用相机应用程序,其中相机视图以模态显示。完成裁剪后。我执行unwind segue到 MainPageViewController 。 (请参见截图)





MainPageViewController 中的我的展开函数如下;

  @IBAction func unwindToMainMenu(segue:UIStoryboardSegue){
self.performSegueWithIdentifier(Categories,sender:self)
}

其中categories是来自的push segue标识符MainPageViewController CategoriesTableViewController



程序进入 unwindToMainMenu 函数但它不执行push segue。知道如何解决这个问题吗?



注意:我发现了相同的



3。更新你的unwind @IBAction以执行完成处理程序中的代码



  @IBAction func unwindToMainMenu(segue:UIStoryboardSegue){
如果让segue = segue为? UIStoryboardSegueWithCompletion {
segue.completion = {
self.performSegueWithIdentifier(Categories,sender:self)
}
}
}

您的代码现在将在退出segue完成转换后执行


I am working on a camera app where the camera views are shown modally. After I am done with cropping. I perform an unwind segue to the MainPageViewController. (Please see the screenshot)

My unwind function inside MainPageViewController is as follows;

@IBAction func unwindToMainMenu(segue: UIStoryboardSegue) {
    self.performSegueWithIdentifier("Categories", sender: self)
}

where "categories" is the push segue identifier from MainPageViewController to CategoriesTableViewController.

The program enters the unwindToMainMenu function but it does not perform the push segue. Any idea how to fix this?

Note: I found the same question but the answer suggests to change the storyboard structure.

解决方案

A bit late to the party but I found a way to do this without using state flags

Note: this only works with iOS 9+, as only custom segues support class names prior to iOS9 and you cannot declare an exit segue as a custom segue in storyboards

1. Subclass UIStoryboardSegue with UIStoryboardSegueWithCompletion

class UIStoryboardSegueWithCompletion: UIStoryboardSegue {
    var completion: (() -> Void)?

    override func perform() {
        super.perform()
        if let completion = completion {
            completion()
        }
    }
}

2. Set UIStoryBoardSegueWithCompletion as the class for your exit segue

note: the action for this segue should be unwindToMainMenu to match the original question

3. Update your unwind @IBAction to execute the code in the completion handler

@IBAction func unwindToMainMenu(segue: UIStoryboardSegue) {
    if let segue = segue as? UIStoryboardSegueWithCompletion {
        segue.completion = { 
            self.performSegueWithIdentifier("Categories", sender: self) 
        }
    }
}

Your code will now execute after the exit segue completes its transition

这篇关于在展开segue后执行push segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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