iOS开发点滴

iOS返回跳到指定控制器 & 移除指定控制器

2022-09-06  本文已影响0人  不要虚度美好的时光

1. iOS返回跳到指定控制器

    // 返回指定控制器
    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:[InboxViewController class]]) {
            [self.navigationController popToViewController:controller animated:YES];
        }
    }

2. 移除指定控制器

方法a:

NSArray* tempVCA = [self.navigationController viewControllers];

for(UIViewController *tempVC in tempVCA)
{
    if([tempVC isKindOfClass:[urViewControllerClass class]])
    {
        [tempVC removeFromParentViewController];
    }
}

方法b:

NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];
[navigationArray removeObjectAtIndex: 2]; 
self.navigationController.viewControllers = navigationArray;
上一篇下一篇

猜你喜欢

热点阅读