简体   繁体   中英

How to return to view controller in main.storyboard from a xib without using navigation controller or navigation bar?

I am making an app with different view controllers. My home screen is in main.storyboard . Rest of the view controllers have their own xib , .h & .m files. I am trying this for navigation from home screen.

-(IBAction)btnSignUpTapped:(id)sender
{
    SignUpWithEmailViewController * login = [[SignUpWithEmailViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc]
                                   initWithRootViewController:login];
    [self presentViewController:nav animated:YES completion:NULL];
}

This code works fine for navigating to different viewcontroller (in this case SignUpwithEmailViewController ). On SignUpWithEmailViewController I have a back button which is supposed to bring me back to home screen. This is what I got so far:

-(IBAction)btnBackTapped:(id)sender
{
    ViewController * homeScreen = [[ViewController alloc] init];

    UINavigationController *nav = [[UINavigationController alloc]
                                   initWithRootViewController:homeScreen];
    [self presentViewController:nav animated:YES completion:NULL];
}

But as result of this code, screen turns black and nothing happens. How do I solve this problem? For hiding the nav bar I am using

-(void) viewWillAppear:(BOOL)animated
{
[[self navigationController] setNavigationBarHidden:YES animated:NO];
}

Yes, you have to insert you called viewController to NavigationController, but if you wont to use modal flow - to close presentedViewController just call:

[self dismissViewControllerAnimated:YES completion:^{

}];

EDITED:

may be it will be more helpful, it just example, put it to you main view controller:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    UIViewController *c = [[UIViewController alloc] init];
    c.view.backgroundColor = [UIColor redColor];

    [self presentViewController:c animated:YES completion:^{
        [self dismissViewControllerAnimated:YES completion:^{

        }];
    }];
}

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