我有三个 Controller ,我想知道 Controller 是推送还是弹出
Controller :
{
if(!b)
b = [B alloc] init];
[self.navigationController pushViewController:b animated:YES];
}
B Controller :
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
//I want here to judge, from the "A" push over, or to return from the "C" "pop"
//if it is push from A
//dosomething.....
//if it is pop from C
//dosomething
}
-(void)testAction:(id)sender
{
C *c = [[C alloc] init];
[self.navigationController pushViewController:b animated:YES];
[c release];
}
C Controller :
{
[self.navigationController popViewControllerAnimated:YES];
}
谢谢。
最佳答案
看一下 UIViewController 方法,isMovingToParentViewController。如果 View Controller 因为被推送而被显示,这将返回 YES,但如果因为另一个 View Controller 从堆栈中弹出而显示它,则返回 NO。
-(void)viewDidAppear:(BOOL)animated { //Code in view controller B
[super viewDidAppear:animated];
NSLog(@"isMovingToParentViewController: %d",self.isMovingToParentViewController);
// this will log 1 if pushing from A but 0 if C is popped
}
关于ios 如何知道 Controller 返回的是 "push"还是 "pop",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13226318/