天天看點

顯示NavigationController/NavigationBar和完成傳回動作

在要跳轉至下一個

ViewController

處,建立一個

NavigationController

,并将下一個

VC

作為它的根

VC

,然後顯示

NavigationController

NavigationController

中隻有一個

VC

,是以也就是顯示下一個

VC

):

NextViewController *vc = [[NextNViewController alloc] init];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
    [self presentViewController:navigationController animated:YES completion:^{
    }];
           

接着,在

NextViewController

添加傳回按鈕,并傳回父視圖:

- (void)viewWillAppear:(BOOL)animated {
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(goBack)];
    [self.navigationItem setLeftBarButtonItem:backItem];
}

- (void)goBack {
    [self.navigationController dismissViewControllerAnimated:YES completion:^{
    }];
}
           

繼續閱讀