本文介绍了在ModalViews之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:

1.显示基于导航控制器的视图

2.用户选择选项

3.显示模态视图A

4.用户在模态视图中选择另一个选项A

5.隐藏模态视图A

6.  显示模态视图B

Scenario:
1. Show navigation controller based view
2. User select option
3.   Show modal view A
4. User select another option in modal view A
5.   Hide modal view A
6.   Show modal view B

// This function must show modal view A
This scenario implemented like this:
- (IBAction)showModalViewA:(id)sender {
    ModalViewA *viewA = [[ModalViewA alloc] forParent:self];
    [self presentModalViewController:viewA animated:YES];
    [viewA release];
}

// This function must hide modal view A and show modal view B
- (void)didSelectOptionInViewA {
    ModalViewB *viewB = [[ModalViewB alloc] init];
    viewB.peoplePickerDelegate = self;

    [self dismissModalViewControllerAnimated:NO];            // Problem Is Here
    [self presentModalViewController:viewB animated:YES];
    [viewB release];
}

请查看标记为 strong>

当我设置 dismissModalViewControllerAnimated:NO 时,它可以正常工作。
如果此参数为 YES ,则viewB不会显示在屏幕上。

Please look at line marked as // Problem Is Here
When I set the dismissModalViewControllerAnimated:NO it works fine.If this parameter is YES then viewB did not appear on the screen.

如何使其与动画一起使用? p>

How to make it works with animation?

推荐答案

动画需要一些时间,比如0.3秒。您无法看到动画完成(没有发送委托方法),因此您可以执行以下两项操作:

The animation will take some time, something like 0.3 seconds. You cannot see when the animation has finished (no delegate methods are being sent) so you can do 2 things:


  1. 显示新的模态视图控制器在一个新的方法,并调用该方法与延迟0.3秒。这不是一个理想的解决方案,因为动画时间可能不同,你永远不能肯定动画已经完成。

  2. 添加一些标志实例变量到你的主视图控制器一个呈现模态视图控制器)并将该标志设置为YES(或使用位,然后一个标志可以包含多个选项)。然后检入 - [UIViewController viewDidAppear:]无论该标志是否被设置,当它是,呈现模态视图控制器。

  1. Present the new modal view controller in a new method and call that method with a delay of 0.3 seconds. This is not an ideal solution because animation times may vary and you can never be sure that the animation has really finished.
  2. Add some kind of a flag instance variable to your main view controller (the one which presents the modal view controller) and set that flag to YES (or do it using bits, then one flag can contain multiple options). Then check in -[UIViewController viewDidAppear:] whether that flag is set and when it is, present the modal view controller.

  1. 您可以确定动画已完成。

  2. 提供模态视图控制器应在其主视图控制器




我真的很奇怪为什么要做这样的事情,因为这真的不是很多苹果。你最好在旧的模式视图中呈现新的模态视图,或者尝试找到另一种设计模式来正确解决问题,这样会更好。

I really wonder why you would want to do such a thing, because this is really not very Apple-ish. You'd better present the new modal view over the old modal view or you try to find another design pattern which solves the problem properly, which would be even better.

这篇关于在ModalViews之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 08:31
查看更多