从当前上下文推送导航
Push navigation from current context
你好,我有两个 Viewcontroller A 和 B,我要介绍 B Controller from A Controller with Current Context 我在下面粘贴了我的代码。我只想从 B 控制器推送到 C 控制器,我知道当我们呈现时没有分配导航控制器,如果我用 rootviewcontroller 呈现 navigationcontroller 我无法实现透明效果。
UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
ChooseAddressVc *sec=[story instantiateViewControllerWithIdentifier:@"ChooseAddressVc"];
sec.myDelegate = self;
sec.modalPresentationStyle = UIModalPresentationOverCurrentContext;
sec.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:sec animated:YES completion:^{
}];
从 Viewcontroller B 推到 C
UIStoryboard*Story=[UIStoryboard storyboardWithName:@"Main2" bundle:nil];
AddNewAddressVc*choose=[Story instantiateViewControllerWithIdentifier:@"AddNewAddressVc"];
[self.navigationController pushViewController:choose animated:YES];
注意:当我呈现当前上下文时,我需要从 B 推送到 C 控制器。 为了更好地理解:我们无法将导航控制器分配为 ROOT VIEWCONTROLLER,因为我们需要获得透明效果
在您的情况下,B 视图控制器中的 self.navigationController
为零。您需要使用 B 视图控制器创建 UINavigationController
作为 rootViewController
。 Present 从 A 创建 UINavigationController
而不是 Present B 视图控制器,之后您可以在 B 视图控制器中使用 self.navigationController
。
您编辑的代码:
UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
ChooseAddressVc *sec=[story instantiateViewControllerWithIdentifier:@"ChooseAddressVc"];
sec.myDelegate = self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:sec];
navController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:navController animated:YES completion:^{
}];
你好,我有两个 Viewcontroller A 和 B,我要介绍 B Controller from A Controller with Current Context 我在下面粘贴了我的代码。我只想从 B 控制器推送到 C 控制器,我知道当我们呈现时没有分配导航控制器,如果我用 rootviewcontroller 呈现 navigationcontroller 我无法实现透明效果。
UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
ChooseAddressVc *sec=[story instantiateViewControllerWithIdentifier:@"ChooseAddressVc"];
sec.myDelegate = self;
sec.modalPresentationStyle = UIModalPresentationOverCurrentContext;
sec.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:sec animated:YES completion:^{
}];
从 Viewcontroller B 推到 C
UIStoryboard*Story=[UIStoryboard storyboardWithName:@"Main2" bundle:nil];
AddNewAddressVc*choose=[Story instantiateViewControllerWithIdentifier:@"AddNewAddressVc"];
[self.navigationController pushViewController:choose animated:YES];
注意:当我呈现当前上下文时,我需要从 B 推送到 C 控制器。 为了更好地理解:我们无法将导航控制器分配为 ROOT VIEWCONTROLLER,因为我们需要获得透明效果
在您的情况下,B 视图控制器中的 self.navigationController
为零。您需要使用 B 视图控制器创建 UINavigationController
作为 rootViewController
。 Present 从 A 创建 UINavigationController
而不是 Present B 视图控制器,之后您可以在 B 视图控制器中使用 self.navigationController
。
您编辑的代码:
UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
ChooseAddressVc *sec=[story instantiateViewControllerWithIdentifier:@"ChooseAddressVc"];
sec.myDelegate = self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:sec];
navController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:navController animated:YES completion:^{
}];