【问题标题】:Popping to first view controller of the project弹出到项目的第一个视图控制器
【发布时间】:2012-03-24 15:06:20
【问题描述】:

我有一个UINavigationController。我在上面加载了presentmodalviewcontroller。我在presentmodalviewcontroller 上再推 2 个视图控制器。如果我需要移动到我的第一个视图控制器,应该怎么做?

编辑:我还在堆栈顶部的UIViewController 上加载了一些UIView。我已成功删除它。

我试过了

 [self.navigationController popToRootViewControllerAnimated:YES];
 [self.navigationController dismissModalViewControllerAnimated:YES];  
 [self.navigationController popToViewController:[self.navigationController.viewControllers   objectAtIndex:0] animated:YES]; 

但还是不行

这就是我添加每个视图控制器的方式

第一个视图控制器

 FirstViewController *firstViewController = 
 [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];

 UINavigationController *navcontrol =[[UINavigationController alloc]initWithRootViewController:firstViewController];
 [self presentModalViewController:navcontrol animated:YES];
 [navcontrol release];

第二个视图控制器

SecondViewController *secondViewController = [[SecondViewController alloc]init] ;
[self.navigationController pushViewController: secondViewController animated:YES];
        [secondViewController release];

第三个视图控制器

ThirdViewController *thirdViewController = [[ThirdViewController alloc] init];
[self.navigationController pushViewController: thirdViewController animated:YES];
[thirdViewController release];

【问题讨论】:

  • 如果我说答案是 -popToRootViewController:animated,你会不会面子?
  • 我试过 [self.navigationController popToRootViewControllerAnimated:YES]; [self.navigationControllerdismissModalViewControllerAnimated:YES]; [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];但它仍然无法正常工作
  • 您为什么不尝试推送到您的 firstViewController 而不是这样做?
  • 我不想创建新实例
  • 您能否展示您如何将 viewControllers 放置在导航堆栈上的代码?

标签: iphone ios uiviewcontroller uinavigationcontroller


【解决方案1】:

好的。我明白了。

    myAppDelegate *appDelegate = (myAppDelegate*)[UIApplication sharedApplication].delegate;

    [appDelegate.navigationController dismissModalViewControllerAnimated:YES];

【讨论】:

    猜你喜欢
    • 2013-07-25
    • 1970-01-01
    • 2020-10-04
    • 1970-01-01
    • 1970-01-01
    • 2013-10-25
    • 2017-04-22
    • 2019-07-03
    • 1970-01-01
    相关资源
    最近更新 更多