如何从多个视图控制器中的最后一个View控制器移动到第一个viewController [英] How to move to First viewController from last View controller among multiple view controllers

查看:122
本文介绍了如何从多个视图控制器中的最后一个View控制器移动到第一个viewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii ...我是iPhone编程的新手..有人可以帮帮我...... !!
我有多个viewControllers..in第一个ViewController叫做HomeViewController我调用了方法[self presentModalViewController:aboutViewController animated:YES];在一个IBAction中,aboutButton移动到AboutViewController
,在AboutViewController中我调用了方法[self presentModalViewController:ContactUsViewController animated:YES];移动到那个视图控制器和另一个方法[self dismissModalViewControllerAnimated:YES];回到HomeViewController。



在第3个,ContactUSViewController我调用了方法[self dismissModalViewControllerAnimated:YES];回到AboutViewController ..我想去从这里直接到HomeViewController(ContactUsViewController).i使用[self presentModalViewController:homeViewController animated:YES];但它不起作用......



如何做到这一点......?



谢谢你.. <根据 doco for dismissModalViewControllerAnimated


如果你连续出现几个模态视图
控制器,那么
构建一组模态视图
控制器,调用这个方法在
视图控制器中位于堆栈中较低的
解除其直接子视图
控制器和所有视图控制器
高于该堆栈上的子节点。当
发生这种情况时,只有最顶层的视图
以动画方式被解雇;
任何中间视图控制器只需从堆栈中删除


所以从 ContactUsViewController 您需要在 HomeViewController 上调用 dismissViewControllerAnimated 。您可以通过 parentViewController 属性访问该视图控制器。所以你在 ContactUsViewController 的dismissAction中的代码是:

   - (IBAction)dismissAction:(id )sender 
{
//得到你的父(即AboutViewController)
UIViewController * parent = self.parentViewController;

//得到它的父(即HomeViewController)
[parent.parentViewController dismissModalViewControllerAnimated:YES];
}

可能有更好的方式来到 HomeViewController ,但对于你的浅层视图控制器,这应该没问题(我试过这个并且它有效)。


Hii...i am new to iPhone programming..can anybody help me out please...!! I have multiple viewControllers..in First ViewController called HomeViewController i called the method [self presentModalViewController:aboutViewController animated:YES]; in a IBAction for aboutButton to move to AboutViewController and in the AboutViewController i called the method [self presentModalViewController:ContactUsViewController animated:YES]; to move to that view controller and one more method [self dismissModalViewControllerAnimated:YES]; to go back to HomeViewController.

in the 3rd, ContactUSViewController i called the method [self dismissModalViewControllerAnimated:YES];to go back to the AboutViewController..and i want to go directly to HomeViewController from here(ContactUsViewController).i used [self presentModalViewController:homeViewController animated:YES]; but its not working...

How to do that...?

Thank u..

解决方案

According to the doco for dismissModalViewControllerAnimated:

If you present several modal view controllers in succession, and thus build a stack of modal view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack.

So from your ContactUsViewController you need to call dismissViewControllerAnimated on the HomeViewController. You can access that view controller through parentViewController property. So your code in the dismissAction for the ContactUsViewController is:

- (IBAction)dismissAction:(id)sender
{
    // get your parent (ie AboutViewController)
    UIViewController * parent = self.parentViewController;

    // get its parent (ie HomeViewController)
    [parent.parentViewController dismissModalViewControllerAnimated:YES];
}

There might be a better way of getting to your HomeViewController, but for your shallow stack of view controllers, this should be fine (I tried this out and it worked).

这篇关于如何从多个视图控制器中的最后一个View控制器移动到第一个viewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆