第一、多次navigation之后,想直接返回跳到指定页面:(此种情况是一个导航栏)
//返回上一级视图
UIViewController *viewCtl =self.navigationController.viewControllers[1];
[self.navigationController popToViewController:viewCtl animated:YES];
navigation对应的是返回函数是pop,而且是以入栈的方式推出页面,root根视图是0,自己对应要跳到哪个页面算一下就好。
第二种方法:遍历之前所有的push控制器,跳到指定的。 (此种情况是多个导航栏)
for (UIViewController *controller in self.navigationController.viewControllers) {
if ([controller isKindOfClass:[要返回的类名 class]]) {
[self.navigationController popToViewController:controller animated:YES];
}
}
如果是直接想返回到根视图的话:
[self.navigationController popToRootViewControllerAnimated:YES];
第二、present对应的是返回函数是dismiss,去除present的那个页面:
[self dismissViewControllerAnimated:YES completion:nil];
如果是多次present之后:
- (void)logoutBtnOnClick
{
TargetVC *target = [[TargeVC alloc] init];
UIViewController *vc = self.presentingViewController;
if (!vc.presentingViewController) return;
while (![vc isKindOfClass:[target class]]) {
vc = vc.presentingViewController;
}
[vc dismissViewControllerAnimated:YES completion:nil];
}
第三、由app跳转到手机设置页面:调用openURL
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=WIFI"]];
}else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];
}
其他的要求自己更换相应的NSURL即可。