问题描述
- 返回后视图的导航条消失了
- 使用 storyboard 创建了一个带有 navigation bar 的项目。其中有从ViewA点击一个按钮打开ViewB的功能,这一段实现了。然后我用一个取消键返回ViewA。在取消之后,返回ViewA成功了,但是导航条没有显示。而且是ViewA中有导航条,ViewB中没有。
请高手指点一下,谢谢。
View A:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@""MainStoryboard"" bundle:nil]; EditViewController *viewController = (EditViewController *)[storyboard instantiateViewControllerWithIdentifier:@""EditViewController""]; [self presentViewController:viewController animated:NO completion:NULL];
View B:
- (IBAction)cancelButtonPressed:(id)sender { if ( lables != NULL) { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@""MainStoryboard"" bundle:nil]; ScannerViewController *viewController = (ScannerViewController *)[storyboard instantiateViewControllerWithIdentifier:@""ScannerViewController""]; [self presentViewController:viewController animated:NO completion:NULL]; } else{ [self.navigationController popViewControllerAnimated:YES]; }
解决方案
实现self.navigationController
弹出展现viewB。要用到presentviewcontroller 和dismissviewcontroller
[self dismissViewControllerAnimated:YES completion:nil];
根据你的情况最好用到UINavigationController
e.g
推出:
[self.navigationController pushViewController:viewController animated:YES];
关闭:
[self.navigationController popViewControllerAnimated:YES];
时间: 2024-10-31 03:30:29