ios - Using a String in another View Controller -
i have label in mainviewcontroller
swift app i'm developing. part of mainviewcontroller
determine user's location , display on screen. now, if user decides use location (instead of typing in own if looking city) want display title of next viewcontroller after press button. i'm not sure how accomplish this. i've tried declare var labeltext: string
assigned string representing user's location global variable, compile error mainviewcontroller not initialized, , not build.
can me out here? thanks!
the best way pass string mainviewcontroller next viewcontroller (which i'm going refer nextviewcontroller).
in nextviewcontroller, declare property called pagetitle:
var pagetitle: string?
i assuming there segue mainviewcontroller nextviewcontroller. in mainviewcontroller's prepareforsegue, pass string so:
var viewc: nextviewcontroller = segue.destinationviewcontroller nextviewcontroller viewc.pagetitle = "title"
then in nextviewcontroller's viewdidload, can make title of screen whatever passed mainviewcontroller:
if self.pagetitle != nil { self.title = self.pagetitle }
Comments
Post a Comment