有时候开发中需要从VC1 push 到VC2,再从VC2 push 到VC3, VC3完成某件事情后直接 pop到VC1(甚至更深层次pop)
方案1:利用控制器index
int index = (int)[[self.navigationController viewControllers]indexOfObject:self];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:(index -2)] animated:YES];
方案2:反向遍历(降序遍历)
[self.navigationController.viewControllers enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[VC1 class]]||[obj isKindOfClass:[VC0 class]])
{
[self.navigationController popToViewController:obj animated:YES];
*stop = YES;
}
}];