How do I pop the view controller underneath a pushed view controller?

后端 未结 4 699
清酒与你
清酒与你 2021-02-06 01:36

I want to push a view controller onto the stack, then pop the first one that pushed the new one.

-(void) someMethod {
    MegaSuperAwesomeViewController *tempVC          


        
4条回答
  •  星月不相逢
    2021-02-06 01:47

    -(void)popToSelf{
    
        NSArray *array = [self.navigationController viewControllers];
    
        for (int i = 0 ; i < array.count ; i++) {
            UIViewController *currentVC = [array objectAtIndex:i];
            if ([currentVC isKindOfClass:[YourViewControllerClass class]]) {
                [self.navigationController popToViewController:[array objectAtIndex:i] animated:YES];
            }
        }
    }
    

提交回复
热议问题