2

我为 iOS 应用程序中的各种 UI 设置提供了一个模式视图控制器。其中一项设置允许用户选择不同的主视图。当他们点击“完成”时,我想关闭模态视图并让新选择的视图控制器出现,而不会出现旧视图控制器与新视图控制器分离的瞬间延迟。这怎么可能实现?

更新:

这是我使用 Eugene 的技术成功实现的一种方法,但没有应用程序委托。相反,此实现特定于我的场景,其中导航堆栈中的视图控制器在实用程序应用程序中呈现模态视图控制器。

- (void)swapFrontSideViewController;
{
    UINavigationController *navigationVC = (UINavigationController *)[self presentingViewController];
    NSMutableArray *viewControllers      = [NSMutableArray arrayWithArray:navigationVC.viewControllers];
    UIViewControllerSubclass *selectedViewController = nil;
    if ([self.selectedFrontSide isEqualToString:FRONT_SIDE_NAME1]) {
        selectedViewController = [self.storyboard instantiateViewControllerWithIdentifier:FRONT_SIDE_NAME1];
    } else if ([self.selectedFrontSide isEqualToString:FRONT_SIDE_NAME2]) {
        selectedViewController = [self.storyboard instantiateViewControllerWithIdentifier:FRONT_SIDE_NAME2];
    }
    if (selectedViewController) {
        [viewControllers replaceObjectAtIndex:viewControllers.count -1 withObject:selectedViewController];
        [navigationVC setViewControllers:viewControllers];
        self.delegate = selectedViewController;
    } else {
        NSLog(@"Error: Undefined Front Side Selected.");
    }
}
4

1 回答 1

3
- (IBAction)doDismiss:(id)sender {
  AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; // Get the app delegate
  NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:appDelegate.navigationController.viewControllers]; // fetch its navigationController viewControllers stack
  UIViewController *replacementController; //initialize replacement controller
  [viewControllers replaceObjectAtIndex:viewControllers.count -1 withObject:replacementController]; // replace the top view controller in stack with the replacement one
  [appDelegate.navigationController setViewControllers:viewControllers]; //change the stack
  [self dismissModalViewControllerAnimated:YES];
}
于 2012-06-27T13:08:36.813 回答