//返回到上一个视图,比如用户单击导航栏的Back按钮 [[self navigationController] popViewControllerAnimated:YES] //返回到根视图 [[self navigationController] popToRootViewControllerAnimated:YES]; //返回到任意视图 [[self navigationController] popToViewController:destiationViewController animated:YES];
或者说要从一个viewctrollerA中的一个按钮跳转到别的viewcrollerB中,然后从viewcrollerB可以点击返回后返回到主页,
实现方法就是先强制转换到根目录,然后利用根目录的方法调用,进入别的页面
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[self backToFront];
UINavigationController *nav = (UINavigationController *)app.window.rootViewController;
[nav popToRootViewControllerAnimated:NO];
IndexViewController *index=(IndexViewController *)nav.topViewController;
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.tag=3;
[index menuAction:btn];
- (void)backToFront {
[self dismissModalViewControllerAnimated:YES];
}