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

时间:2017-05-22 05:05:55

标签: ios swift swift3 eureka-forms

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

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

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

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

1 个答案:

答案 0 :(得分:2)

如果你已经推出了一个带有segue的新VC,那么你可能想要实现一个协议并定义函数来传回数据。

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

例如:

查看一个(可能是带有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
    }
}