iPhone - 用另一个模态视图覆盖一个模态视图
我有一个主要观点。
从该主视图中,我显示了一个模态视图 (MV1)。
MV1 可能会显示另一个模态视图 (MV2)。
从 MV2 开始,我可能会展示另一个模态视图(MV3)。
所有MV均以动画形式呈现。
我想要的是能够在“杀死”前一个模态视图 (MVx) 之前首先显示(动画)下一个模态视图 (MVx+1)。
如果我在显示之前关闭(动画)MVx MVx+1 : MVx+1 不出现。
如果我在显示 MVx+1 之前关闭(非动画)MVx:会看到 MVx-1。
如果我在关闭(非动画)MVx 之前显示 MVx+1:MVx+1 不会出现。
我该怎么做?
如果您有时间,一些代码示例会有所帮助,但只需详细的解释就足够了。
I have a main view.
From that main view I show a modal view (MV1).
MV1 may show another modal View (MV2).
From MV2, I may show another modal view (MV3).
All that MV are shown animated.
What I want, is to be able to first display (animated) the next modal view (MVx+1) before "killing" the previous one (MVx).
If I dismiss (animated) MVx before showing MVx+1 : MVx+1 does not appear.
If I dismiss (non-animated) MVx before showing MVx+1 : MVx-1 is seen.
If I show MVx+1 before dismissing (non-animated) MVx : MVx+1 does not appear.
How may I do ?
Some code sample would help if you have time, but just a detailed explanation would be enough.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据Apple文档,消除模态视图的可接受方法是让父控制器(即创建模态视图的视图控制器)进行消除。最好的方法是将父控制器设置为模式视图控制器的委托。这里的想法是,模态控制器告诉其父级它已准备好被解雇,并且父级决定从那里采取什么行动方案。
为此,您必须为父控制器实现的模式视图控制器创建委托协议。在您的情况下,您可以在每个 .h 文件的顶部为模态视图创建一个协议来执行此操作(或者如果所有模态视图都可以使用相同的方法来关闭,则在单独的文件中创建一个协议)。例如:
接下来,在每个模态视图控制器中,为委托创建一个实例变量:
当您从当前视图控制器显示模态视图时,将当前控制器设置为委托。
当您想要释放当前模态控制器时,让模态视图控制器在其委托上调用适当的协议方法:
现在,委托可以处理下一步要去哪里。在您的情况下,您可以在 MV3 关闭时通过调用 MV3 中的
[self.delegate Dismiss]
自动关闭 MV2,然后在 MV2 中实现dismiss
如下:According to the Apple docs, the accepted way to dismiss modal views is by letting the parent controller (i.e., the view controller that created the modal view) do the dismissing. The best way to do this is by setting the parent controller as the delegate of the modal view controller. The idea here is that the modal controller tells its parent that it's ready to be dismissed, and the parent decides what course of action to take from there.
In order to do this, you have to create a delegate protocol for the modal view controller that the parent controller implements. In your case, you can create a protocol at the top of each of your .h files for your modal views to do this (or a single protocol in a separate file if all of the modal views can use the same method for dismissal). For example:
Next, in each of your modal view controllers, create an instance variable for the delegate:
When you display a modal view from a current view controller, set the current controller as the delegate.
When you want to release the current modal controller, have the modal view controller call the appropriate protocol method on its delegate:
Now, the delegate can handle where to go next. In your case, you can close MV2 automatically when MV3 closes by calling
[self.delegate dismiss]
in MV3, then implementdismiss
in MV2 as: