1

EDITED

I have been having some issue with passing multiple label.text to another viewController in swift. I can pass one label between the two controllers fine, but I can not make it work to pass multiple. Usually when I try and pass multiple labels when the segue finishes the label on the other side just says label (the name of the the label passing) but not the answer that is supposed to be in the label. If I run it without the segue all the labels post exactly what they should. for instance:

      override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    let breakviewcontroller: BreakAnswer = segue.destinationViewController as! BreakAnswer

    breakviewcontroller.ubrlab1 = ubrLabel1.text!
    breakviewcontroller.ubrlab2 = ubrLabel2.text!
    breakviewcontroller.ubrlab3 = ubrLabel3.text!



}

//this is the other view controller
@IBOutlet weak var ubrAnswer1: UILabel!

@IBOutlet weak var ubranswer2: UILabel!

@IBOutlet weak var ubranswer3: UILabel!



var ubrlab1: String = ""
var ubrlab2: String = ""
var ubrlab3: String = ""








override func viewDidLoad() {
super.viewDidLoad()


ubrAnswer1.text = ubrlab1
ubranswer2.text = ubrlab2
ubranswer3.text = ubrlab3

I have also tried this as making a new let for each one (let breakviewcontroller, breakviewcontroller1... ect) I am sure I have the other view controller set up properly becuase anytime I am sending one I can get it to work. I just started writing code and all of my knowledge has coming from reading things on the internet. Any help would be greatly appreciated. Thanks

Icculus
  • 43
  • 11
  • A tip as you start your coding journey: your code would be much more readable (and your question easier to answer) if you used clearer and more descriptive variable names. You may know what a tsga called sge with a eytd property is, but the internet at large is likely to be flummoxed (as is anyone else who comes across your code for any reason, or perhaps even yourself revisiting the program a few years down the road...) – WendiKidd Apr 28 '16 at 05:46
  • Also, the function doesn't seem to be complete. Have you perhaps missed a few lines in your copy/paste? – WendiKidd Apr 28 '16 at 05:47
  • Sorry I just used an example... that was one I was just messing around with.. I assure you the project that I am making is much more readable (or at least to me) just wanted to throw anything up here and see if there is anyone who know what I am talking about and has any way to help me. – Icculus Apr 28 '16 at 05:49
  • I will edit to something a little more clear to get perhaps a better response – Icculus Apr 28 '16 at 05:53
  • Actually, it helps us a lot more if you could edit to show us your actual code. That way we can make sure there aren't any small differences between your example and your code that you may not notice (and readability definitely helps us as well). :) Just some kind feedback for the future. Welcome to Stack Overflow! – WendiKidd Apr 28 '16 at 05:53
  • Possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Arasuvel Apr 28 '16 at 06:03

1 Answers1

2

With segue

// CurrentViewController

var dictWithDetails = Dictionary<String, AnyObject>()

self.performSegueWithIdentifier("SegueFromCurrentViewControllerToNewViewController", sender: dictWithDetails)


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) 
{

    let objNextViewController : NextViewController =  segue.destinationViewController as! NextViewController

    var dict :Dictionary <String,AnyObject> = (sender as? Dictionary)!

    objNextViewController.dictWithDetails=dict

}

// NewViewController

var dictWithDetails = Dictionary<String, AnyObject>()

// Now use this dictWithDetails in viewWillAppear or viewDidLoad, your all objects from sender class ( CurrentViewController ) will be available here

Without seque

@IBAction func clickToNextViewController(sender: UIButton) {
{

    let objNextViewController = self.storyboard?.instantiateViewControllerWithIdentifier(“ID_NextViewController”) as? NextViewController

    // objNextViewController.properties1 = currentClassproperties1
    // objNextViewController.properties2 = currentClassproperties2

    self.navigationController?.pushViewController(objNextViewController!, animated: true)

}
Hasya
  • 9,792
  • 4
  • 31
  • 46