【问题标题】:How to Pass data from UIPickerView to previous ViewController with NavigationController如何使用 NavigationController 将数据从 UIPickerView 传递到上一个 ViewController
【发布时间】:2020-05-13 23:30:46
【问题描述】:

我正在尝试制作一个设置屏幕,其中 ViewController A 具有 MapView 和 ViewController A 具有将这些引脚放在地图上的功能。

我正在尝试读取 ViewController B 中的 UIPickerView 数据,并通过单击按钮将其发送到 ViewController A。在 ViewController A 中,另一个名为 determineCity() 的函数将评估它收到的数据。

func determineCity(){
    switch incomingData {
    case "0":
        IzmirSelected()
        break
    case "1":
        print("San Francisco")
    default:
        print("Other")
    }
    @IBAction func setCityButtonClicked(_ sender: Any) {
    if selectedData != "-1" {
    self.delegate?.SendDataToViewController(info: selectedData)
    self.navigationController?.popToRootViewController(animated: true)
    }

我尝试了委托方法,它不会将数据发送到 ViewController A。ViewController A 上的代码永远不会改变。

我可以尝试做些什么来将此数据发送到 ViewController A。我做错了什么?

感谢您的帮助!

【问题讨论】:

    标签: ios swift delegates


    【解决方案1】:

    对于代理不工作,这意味着它要么为零

    self.delegate?.SendDataToViewController(info: selectedData)
    

    或分配给另一个不是呈现的实例,另一种方法是这样做

    let all = self.navigationController!.viewControllers 
    let vcB = all[all.count - 2] as! VCBName
    vcB.callMethodHere()
    

    【讨论】:

    • 它似乎仍然没有将 ViewControllerB 的 selectedData 写入 ViewController A 的incomingData。但是您的方法成功执行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-04
    • 2018-10-15
    • 2014-10-04
    • 1970-01-01
    • 1970-01-01
    • 2020-05-12
    • 1970-01-01
    相关资源
    最近更新 更多