簡體   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