本文介绍了如何从多个视图控制器中的最后一个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 AboutViewControllerand 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:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 09:04