ios - Passing NSString via prepareForSegue - Swift -
i'm trying pass string modal view controller seen below, using prepareforsegue method. see below:
here initial view controller present modal view:
override func prepareforsegue(segue: uistoryboardsegue!, sender: anyobject!) { if segue.identifier == "newproject" { var newprojectvc:modalviewcontroller = modalviewcontroller() newprojectvc = segue.destinationviewcontroller modalviewcontroller newprojectvc.teststring = "hello" } }
here modal view controller:
import uikit class modalviewcontroller: uiviewcontroller { var teststring:nsstring! override func viewdidload() { println(self.teststring) } }
here looks in storyboard: ![enter image description here][1]
the problem throws exception on line:
newprojectvc = segue.destinationviewcontroller modalviewcontroller
i have feeling navigation controller unsure, ideas?
you right destinationviewcontroller navigation controller not modalviewcontroller, try that:
let navigationcontroller = segue.destinationviewcontroller uinavigationcontroller let newprojectvc = navigationcontroller.topviewcontroller modalviewcontroller newprojectvc.teststring = "hello"
Comments
Post a Comment