简体   繁体   中英

How to navigate From one view controller to other

I have problem in navigating from one view controller to other.

what I'm doing is If suppose there are 3 view controllers A,B,C then from A I'm pushing to B.

But in B view did load I'm hitting one api and if status code is not 200 I'm pushing to C.

But my problem is only navigation title of C is appearing and every thing is B's view.

Here is code:

 NSLog(@"~~~~~ Status code: %d", [urlResponse statusCode]);

      NSLog(@"Error: %@", [NSHTTPURLResponse localizedStringForStatusCode: urlResponse.statusCode]);

    if([urlResponse statusCode]!=200)
    {



      TermsAndConditions * view = [self.storyboard instantiateViewControllerWithIdentifier:@"TermsAndConditions"];



        self.navigationController.navigationBar.topItem.title = @"";
        [self.navigationController pushViewController:view animated:YES];
}

Just drag from a button or any other object to another viewController in stroyboard. it is the simple way.

and the another method is

Import The viewController example: #include "SecondViewController"

then define it in .m file where u want to take the navigation

 SecondViewController *tempVC =[[SecondViewController alloc]
 initWithNibName:@"homeViewController" bundle:nil];
 [self.navigationController pushViewController:tempVC animated:YES];

but here pushViewController does not carry the navigation properties if u need navigation properties in SecondViewController write like this

 SecondViewController *tempVC =[[SecondViewController alloc]
 initWithNibName:@"homeViewController" bundle:nil];
 [self.navigationController presentedViewController:tempVC animated:YES]

it works for your definitely.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM