在 segue 关闭时执行操作 [英] Perform action when segue is closed

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

问题描述

我有一个 ViewController,我在其中调用了另一个 ViewController 的 segue:

 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {如果 segue.identifier == blogSegueIdentifier {让目的地 = segue.destination 作为!回复让路径 = tableView.indexPathForSelectedRowlet cell = tableView.cellForRow(at: path!) as!问题标签单元格destination.blogName = String(cell.labelQues!.tag)}}

在打开的 segue (ViewController) 中,UINavigationBar 中有一个 UITextView 和一个发送按钮.因此,用户输入 textView 并将其发送到服务器,点击按钮,在此打开的 segue (ViewController) 关闭后,用户返回到第一个 ViewController.用户在不使用 viewWillAppear 的情况下关闭 segue 时如何调用第一个 ViewController 中的方法?

解决方案

你好 @Mr Jo 你可以使用 unwind segue 来达到这个目的.

在你的第一个 viewController 中声明一个方法,比如:-

<前>//MARK: - - Unwind Segue 从选择的类别中获取数据@IBAction func unwindToAssignCatController(segue: UIStoryboardSegue) {//从selectcategory类中取回数据如果 segue.identifier == "segueIdentifier"{让控制器 = segue.source as!回复//从第二个 viewController 获取你的值并在第一个 viewController 中使用}

之后你必须选择你的第二个 ViewController

1: 右键单击​​控制器并拖动退出然后会出现下面的方法2:选择它并为其分配一个标识符.3:然后在具有相同标识符的第二个 viewController 中对您想要的操作执行 segue.

I have a ViewController where I call segue to another ViewController:

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == blogSegueIdentifier {
            let destination = segue.destination as! Reply
            let path = tableView.indexPathForSelectedRow
            let cell = tableView.cellForRow(at: path!) as! QuestionsTabCell
            destination.blogName = String(cell.labelQues!.tag)
        }
    }

In the opened segue (ViewController) there is a UITextView and a send button in the UINavigationBar. So user inputs textView and sends it to server tapping on the button and after this opened segue (ViewController) closes and user returns to first ViewController. How to call a method in first ViewController when user closes segue without using viewWillAppear?

解决方案

Hello @Mr Jo You can use unwind segue for this purpose.

declare a method in your first viewController Like :-


    //MARK: - - Unwind Segue get data from select categories
    @IBAction func unwindToAssignCatController(segue: UIStoryboardSegue) {

        //get back data from selectcategory class
        if segue.identifier == "segueIdentifier"{

            let controller = segue.source as! Reply
            // get your values from second viewController and use in first viewController
        }


After that you have to select your second ViewController

1: right Click on Controller and drag on exit then below method will appear 2: Select it and assign an identifier to it. 3: then perform segue on that action where you want in second viewController with same identifier.

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

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