ios - 一种消除 `modalViewController` 并呈现另一个的方法

标签 ios modalviewcontroller

问题是:我有一个 modalViewController,它带有一个触发 IBAction 的按钮,如下所示:

-(IBAction)myMethod
{
    [self dismissModalViewControllerAnimated:YES];

    if([delegate respondsToSelector:@selector(presentOtherModalView)])
    {
        [delegate presentOtherModalView];
    } 
}

在作为 modalViewController 委托(delegate)的 Root View 中,我实现了 presentOtherModalView 委托(delegate)方法,它看起来像这样:

    -(void)presentOtherModalView
{

     AnotherViewController *viewInstance = [[AnotherViewController alloc]initWithNibName:@"AnotherViewController" bundle:nil];

     viewInstance.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

     [self presentModalViewController:viewInstance animated:YES];

    [viewInstance release];
}

问题是第二个 modalViewController 没有被呈现。它给我消息 wait_fences: failed to receive reply: 10004003...这应该怎么做?

最佳答案

因为它们是紧接着彼此执行的(它们不等待 View 消失/出现),所以它不会被执行。因为一次只能有一个 ModalViewController 出现在屏幕上,所以你必须先等待另一个 ModalViewController 消失,然后下一个才会出现在屏幕上。

你可以按照你想要的方式创造性地做到这一点,但我这样做的方式是这样的:

[self dismissModalViewControllerAnimated:YES];
self.isModalViewControllerNeeded = YES;

然后在底层 ViewController 的 viewDidAppear 方法中,我这样做:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    if (self.isModalViewControllerNeeded) {
        [self presentModalViewController:viewInstance animated:YES];
        self.isModalViewControllerNeeded = NO;
    }
}

希望对您有所帮助!

关于ios - 一种消除 `modalViewController` 并呈现另一个的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12005984/

相关文章:

ios - 使用 Swift 3 将数据从 Modal Viewcontroller 传递到 rootController(不要 Segue)

iphone - iPad - 当有多个时,最顶层的模态视图 Controller 不会关闭

iphone - 如何检测父 View Controller 中模态视图 Controller 的解除?

iphone - UISearchBar - 范围栏动画

ios - UITableViewControllers 上的 prepareforSegue 方法

ios - 收到 apn 时的后台任务

iphone - 如何将模态视图添加到当前 View Controller 上?

ios - 离线博客阅读(图片)能力(缓存)?

objective-c - 如何在显示搜索栏时将 tableView 的编辑按钮放在工具栏中(如在 Apple 的邮件应用程序中)?

ios - 多个模态视图点击即可关闭