通过展开段传递数据 [英] Pass data through unwind segue

查看:15
本文介绍了通过展开段传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在到处寻找这个问题的答案……我不知道如何通过展开段传递数据。我知道我应该使用prepareForSegue,但我不确定我应该放什么。我正在尝试从一个类中的UIPickerView传递变量(MyLabel):

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    myLabel.text = pickerData[row]
}

到另一个班级。我已经有了展开段代码,但不知道要将prepaareForSegue放在哪里以及要放入什么内容。

如果我的问题需要进一步澄清,请告诉我。

推荐答案

如果我正确理解了您的问题,您应该这样做:

class MyPickerController : UIViewController {
  @IBOutlet weak var myLabel: UILabel!

  var pickerData:[String]

  func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    myLabel.text = pickerData[row]
    performSegueWithIdentifier( "mySegueName", sender: self )
  }

  func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if let myController = segue.destinationController as? MyDestinationViewController {
      myController.text = myLabel.text
  }
}

它将把标签文本传递给MyDestinationViewController实例。 请注意,我传递的不是UILabel对象,而是文本。 您不能将该UILabel对象放在目标控制器接口中,但您可以使用文本并为其设置另一个标签。

这篇关于通过展开段传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆