ios 如何知道 Controller 返回的是 "push"还是 "pop"

标签 ios pushviewcontroller viewdidappear popviewcontroller

我有三个 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/

相关文章:

ios - 在 Swift 中设置动画 UITableViewCell 高亮颜色

ios - 在 cellForRowAtIndexPath 中执行计算是否繁重?

ios - 全屏 PushViewController

iphone - viewDidAppear 和 viewWillAppear 在 iPad 上没有被调用

iOS :GMail API - Send Attachments with email

ios - 遇到应用程序传输安全问题

ios - 在展开的 segue 中弹出到 Root View

swift UITextView setContentOffset 适用于 didappear 而不是 willappear

ios - TableView 单元格的 subview 的框架更改不会发生,直到 View 出现