In XCode 5 and iOS 7 push view controller in ViewDidLoad does not working

Coder_A_D picture Coder_A_D · Oct 30, 2013 · Viewed 8.7k times · Source

Hi I am trying to push a view controller in viewDidLoad

I am using storyboard. In ViewDidLoad, I am checking that user is login and he is created his profile. if user is not logged in or he does not created his profile then pushing the another view controller for login/profile view. The following code does not working.

- (void)viewDidLoad

if(USER_IS_LOGGED_IN)
{
    if(USER_PROFILE_COMPLETED)
    {
       [self sendRequest];
    }
    else
    {
        //push profile view      
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        ProfileViewController *profileViewController = (ProfileViewController *)[storyboard instantiateViewControllerWithIdentifier:@"ProfileView"];
        profileViewController.isFromDealView = YES;
        profileViewController.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:profileViewController animated:YES];
    }

    }
    else
    {

    //push login view
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    LoginViewController *loginViewController = (LoginViewController *)[storyboard instantiateViewControllerWithIdentifier:@"LoginView"];
    loginViewController.isFromDealView = YES;
    loginViewController.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:loginViewController animated:YES];


    }

}

Answer

Retro picture Retro · Oct 30, 2013

I am little confuse with your code but any way try this

 - (void)viewDidLoad {

 if(USER_IS_LOGGED_IN) {
    if(USER_PROFILE_COMPLETED)
    {
       [self sendRequest];
    }
    else
    {
        //push profile view      
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        ProfileViewController *profileViewController = (ProfileViewController *)[storyboard instantiateViewControllerWithIdentifier:@"ProfileView"];
        profileViewController.isFromDealView = YES;
        profileViewController.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:profileViewController animated:YES];
    }
 } else {

    //push login view
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    LoginViewController *loginViewController = (LoginViewController *)[storyboard instantiateViewControllerWithIdentifier:@"LoginView"];
    loginViewController.isFromDealView = YES;
    loginViewController.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:loginViewController animated:YES];


    }`
 }