【问题标题】:Eureka row to present view controller and return value in Swift 3.0Eureka 行在 Swift 3.0 中呈现视图控制器和返回值
【发布时间】:2017-05-22 05:05:55
【问题描述】:

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

我确实找到了一件事,但我还是不明白如何将所有这些放在一起:

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

有人可以指点我一个工作示例或帮助我完成此设置吗?

【问题讨论】:

  • 我发现的另一个选项是使用 ButtonRowWithPresent 但我还是想不通。

标签: ios swift swift3 eureka-forms


【解决方案1】:

如果您已经在使用 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
        }
    }
}

视图二(被推送的视图控制器)

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
    }
}

【讨论】:

  • 再次添加答案,因为它已被删除。如果它解决了OP中的问题,请接受答案。
猜你喜欢
  • 2016-10-12
  • 2015-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-30
  • 2017-07-09
  • 2014-10-09
相关资源
最近更新 更多