2

Okay, so far I've two view controllers in my storyboard. One with "login" elements and other as "User's home" sort of thing. I am intending to do the following : When user clicks on login, there's a bit of processing and then it should show to user's home screen..

When I do it via storyboard, i mean = control drag "login" button to user's home view it works fine. But I cant use that as I've to process the login data. It also shows some animation meanwhile. So, I've to do this shift programmatically. I wrote following code in the login button's IBAction ::

HomeViewController *homeView = [[HomeViewController alloc] init];

[self presentViewController:homeView animated:YES completion:NULL] ;

Now, this takes user to the intended view. However, the elements in the homeview (say a label, navigation bar are not being shown. And thats what my worry is. (In theory, I can build entire view programatically but i think thats not the proper way of doing this, is it ? I want to make use of storyboard functionality in full i.e. design maximum UI in storyboard and use them from the backend how you want them to work.)

How do I do it ?

Cheers.

PS : I intend to add few more view controllers so at the moment i didn't think of navigation controller. not sure, if i should use it.

Sukhi
  • 13,261
  • 7
  • 36
  • 53

2 Answers2

2

Using storyboards you should be using:

UIViewController *homeView = [self.storyboard instantiateViewControllerWithIdentifier:@"someID"];
[self presentViewController:homeView animated:YES completion:NULL] ;

Then set the ID to the view controller in storyboard like so:

enter image description here

Additionally, if you wish to there is absolutely nothing wrong with designing your UI entirely in code. Personally I prefer it. It gives you much more flexibility than interface builder.

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
2

In addition to NSPostWhenIdle's suggestion of instantiateViewControllerWithIdentifier, you can also define a segue between the two view controllers (not between the button and the second controller, but between the two view controllers):

Segue between controllers

Then give the segue a unique identifier, and then have your IBAction method do a performSegueWithIdentifier. This way your storyboard will continue to visually represent the various relationships between your view controllers.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • Thanks. Unfortunately, I cant mark both the answers as "answered". – Sukhi Aug 26 '12 at 15:47
  • Hey man...I'd tried that...but they said i didnt have sufficient "reputations"....which i just got any way. :) Thanks once again for your help. – Sukhi Aug 26 '12 at 16:09