Search code examples
iosxcodepushviewcontroller

Push View Controller not showing elements added from storyboard


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.


Solution

  • 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.