1

Im trying to pass this dictionary to another view controller

func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "goToThird" {
        let Ps = segue.destination as! ThirdViewController
        Ps.hourDictionary = Time //time is a dictionary
    }
}

// Trigger send

@IBAction func buttonPressed(_ sender: Any) {
    performSegue(withIdentifier: "goToThird", sender: self)
}

and this is the code in the destionation view controller:

var hourDictionary : Dictionary = ["String" : "String"]

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as! TableViewCell

    print(hourDictionary)
    cell.label2.text = hourDictionary["\(indexPath.row)"]

    return cell
}

However hourDictionary remains with this value:

["String": "String"]
["String": "String"]
["String": "String"]
["String": "String"]
["String": "String"]
["String": "String"]

Time is being initialized as a dictionary:

    var eatingTime : Dictionary = ["String" : "String"]

Already tried to replace the func Prepare for segue but still not working:

   override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "goToThird" {
        let Ps = segue.destination as! ThirdViewController
        Ps.hourDictionary = Time
    }
}

0 Answers0