繁体   English   中英

Eureka行在Swift 3.0中显示视图控制器和返回值

[英]Eureka row to present view controller and return value in Swift 3.0

我正在寻找帮助,找出如何在MultivaluedSection中有一行呈现具有第二个Eureka形式的视图控制器,并将值返回到MultivaluedSection行。 我已经能够使用常规ButtonRow使用segue推送视图控制器,但我无法弄清楚是不是将值返回到MultivaluedSection中的行。 我不确定ButtonRow方法是否支持返回值,所以我开始寻找其他解决方案。 我找到的是使用自定义演示者行( https://github.com/xmartlabs/Eureka#custom-presenter-rows ),但我不明白如何使其工作。

这里有一件事我找到了,但又一次,我不明白如何把这一切放在一起:

帮助创建简单的自定义Presenter行 - https://github.com/xmartlabs/Eureka/issues/716

有人可以指出我的工作样本或帮助我完成这个设置吗?

如果您已经使用segue推送新VC,那么您可能希望实现协议并定义函数以将数据传回。

是一个很好的导航控制器教程,最后添加了一个协议。

例如:

查看一个(可能是带有ButtonRow的窗体视图控制器)

class FormVC: FormViewController , FooViewControllerDelegate{
    var text : String!
    override func viewDidLoad() {
        super.viewDidLoad()

    }

    /// Delegate protocol callback implementation
    func myVCDidFinish(controller: FooViewController, text: String) {
        // Receive the data as a delegate
        self.text = text
        // In this case we also want to finish the view
        controller.navigationController?.popViewController(animated: true)
    }

    /// This represents the prepare for segue mentioned as implemented in the question
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Act upon the segue we want from this VC
        // The string is defined in the storyboard, so it must be exactly the same
        if segue.identifier == "mySegue"{
            // Creating the second VC instance
            let vc = segue.destination as! FooViewController
            // Since this class is now a delegate, setup the delegate
            vc.delegate = self
        }
    }
}

查看两个(推送的View控制器)

protocol FooViewControllerDelegate {
    func myVCDidFinish(controller: FooViewController, text: String)
}

class FooViewController: UIViewController {
    /// Data
    var text : String!

    /// Set up an optional delegate
    var delegate:FooViewControllerDelegate? = nil

    override func viewDidLoad() {
        super.viewDidLoad()
        // Init label
        self.text = "Pushed view data to pass back
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM