pass value of pickerView from viewcontroller

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

pass value of pickerView from viewcontroller

Bjorn Chin Fo Sieeuw
I would like to navigate to myViewController2, choose a value from the picker, and then this value must be passed to the window I come from. Code in the window:

    class func nodeWithAtom14(atom:SCNGeometry, molecule: SCNNode,position:SCNVector3) -> SCNNode {

        var myPicker: UIPickerView!

        let node = SCNNode(geometry: atom)

        node.position = position

        molecule.addChildNode(node)


        var myCustomViewController: myViewController2 = myViewController2(nibName: nil, bundle: nil)

        var getThatValue = myCustomViewController.content//pickerView3(myPicker,didSelectRow:1,inComponent:1)

        println(getThatValue)


        return node

    }



Code in myViewController2:


    var content: String = "hello"


//...


func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {

        return 1

    }

    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {

        return pickerData.count

    }

    //MARK: Delegates

    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {

        return pickerData[row]

    }

    

    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) -> String! {

        myLabel.text = pickerData[row]

        content = "i"

        if(pickerData[row] == "Mozzarella"){

            let path = NSBundle.mainBundle().pathForResource("mozzarella", ofType: "txt")

            var possibleContent = String(contentsOfFile:path!, encoding: NSUTF8StringEncoding, error: nil)

            if var content = possibleContent {

            }

        }

        if(pickerData[row] == "Gorgonzola"){

            let path = NSBundle.mainBundle().pathForResource("gorgonzola", ofType: "txt")

            var possibleContent = String(contentsOfFile:path!, encoding: NSUTF8StringEncoding, error: nil)

            if var content = possibleContent {

            }

        }

        return content

    }


I would like to change 'content' with the picker, and then print it out in the Xcode console using println(getThatValue) in the first window. Right now it is just printing out 'hello' only once. How can I do that?

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/28c7fb49-849c-4c9f-b06f-0b7de2e06c27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.