Passing array through segue in swift

后端 未结 3 1117
南笙
南笙 2021-01-24 08:20

I\'ve been struggling for a few days now with passing an array from my SecondViewController to my FirstViewController using Swift.

From my rese

3条回答
  •  再見小時候
    2021-01-24 08:44

    Your code looks fine, use the following prepareforsegue as it helps figure out where the problem could be

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "segueIdInStoryboard" {
            if let DVC = segue.destinationViewController as? FirstViewController{
                DVC.mySeguedArray = myIncomeArray
            } else {
                print("Data NOT Passed! destination vc is not set to firstVC")
            }
        } else { print("Id doesnt match with Storyboard segue Id") }
    }
    
    class FirstViewController: UIViewController 
    {
         @IBOutlet weak var textView: UITextView!
         var myIncomeArray: [Income]!
         var mySeguedArray: [Income]!{
             didSet{
                 myIncomeArray = mySeguedArray //no need to call viewDidLoad
             }
         }
    }
    

提交回复
热议问题