我有UIViewCOntroller
,我的代码如下。
TviewController *tviewController = [[TviewController alloc]init];
[self.navigationController pushViewController:tviewController animated:YES];
现在从TviewController
我转到另一个viewCOntroller;
XviewController *xviewController = [[XviewController alloc]init];
[self.navigationController pushViewController:xviewController animated:YES];
在此XviewController
中有一个按钮,当我点击该按钮时,我需要将 BACK 移动到TviewController
我如何以编程方式执行此操作?
注意:我不想使用pushViewController
并进一步推送它。我需要回到TviewController
(就像点击两次后退按钮一样)
答案 0 :(得分:3)
答案 1 :(得分:3)
[self.navigationController popViewControllerAnimated:BOOL)]
[self.navigationController popToViewController:(UIViewController *) animated:(BOOL)];
[self.navigationController popToRootViewControllerAnimated:(BOOL)];
是返回层次结构的方法
答案 2 :(得分:1)
有三种可能的方法。
使用popToRootViewControllerAnimated:
- >返回根视图控制器(第一个视图控制器)
使用popViewControllerAnimated:
- >向后走1.它与后退按钮完全相同。
使用popToViewController:animated:
- >回到你想要的UIViewController
(只要它在后面堆叠)。
第1点& 2很容易实现,其他答案会引导您到那里。
对于第3点,这里是:
@class TviewController.h;
@interface XviewController : UIViewController
{
//this is XviewController.h
//you may use `#import` other than use `@class` but on some reason you can't, if you use`#import XviewController.h` in your TviewController class.
}
//XviewController.m
#import TviewController.h
#import XviewController.h
@implementation
-(IBAction) backTviewController
{
for ( UIViewController *viewController in self.navigationController.viewControllers )
if ( [viewController isMemberOfClass:[TviewController class]]{
[self.navigationController popToViewController:viewController animated:YES];
break;
}
}