Friday, 15 May 2015

ios - View Controller not loading Storyboard View -



ios - View Controller not loading Storyboard View -

i new ios development. have story board 2 view controllers, link them uiviewcontroller classes, works when seek load sec class first class (like splash screen going main menu) 'menu' not load view storyboard. loads black screen. have assigned class viewcontroller in right hand sidebar of storyboard , coloured screen reddish see if loads class, does, if take reddish out, loads black screen, not desired screen storyboard.

screen 1's (splash)'s code:

func switchscreen() { allow secondviewcontroller:vcmainlogin = vcmainlogin() self.presentviewcontroller(secondviewcontroller, animated: true, completion: nil) } override func viewdidload() { super.viewdidload() nstimer.scheduledtimerwithtimeinterval(1.0, target: self, selector: "switchscreen", userinfo: nil, repeats: false) }

screen 2's (login / menu)'s code:

override func viewdidload() { super.viewdidload() self.view.backgroundcolor = uicolor.redcolor() // additional setup after loading view. }

it loading because colour of screen turns red, when take out loads black, not screen storyboard.

you need instantiate view controller storyboard , not create via initialize function. need assign view controller storyboardid in interface builder (view -> utilities -> identity inspector). in illustration load view controller storyboard id of "vc2" storyboard named "mainstoryboard".

let mainstoryboard = uistoryboard(name: "mainstoryboard", bundle: nsbundle.mainbundle()) allow vc : uiviewcontroller = mainstoryboard.instantiateviewcontrollerwithidentifier("vc2") uiviewcontroller

here equivalent objective-c code reference

uistoryboard *mainstoryboard = [uistoryboard storyboardwithname:@"mainstoryboard" bundle:[nsbundle mainbundle]]; uiviewcontroller *vc = [mainstoryboard instantiateviewcontrollerwithidentifier:@"vc2"];

ios iphone uiviewcontroller swift

No comments:

Post a Comment