pass value of pickerView from viewcontroller

16 views
Skip to first unread message

Bjorn Chin Fo Sieeuw

unread,
Jan 15, 2015, 7:29:53 AM1/15/15
to swift-l...@googlegroups.com
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?

Reply all
Reply to author
Forward
0 new messages