【问题标题】:Viewcontroller not getting pushed to stackViewcontroller 没有被推入堆栈
【发布时间】:2011-02-27 19:29:35
【问题描述】:

我对 iPhone 还很陌生。我有一个特殊的问题。我正在将视图控制器作为子视图添加到当前视图。然后我想从中推送一个新的视图控制器。问题是当我尝试执行 pushViewController 时,它没有响应。

例如,在 CurrentViewController 中我添加了 NewViewController 的视图作为子视图

[self.view addSubView : NewViewController.view]

现在在 NewViewController 中,单击一个按钮,我正在执行以下操作:

SecondViewController *secondVC = [SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];

这里第二个VC没有被压入堆栈。

【问题讨论】:

  • 子视图会有导航控制器吗?
  • @Jayashree。您是否使用过视图控制器应用程序或基于导航的应用程序?
  • @Pugal : CurrentViewController 和 NewViewController 是基于视图的,而 SecondViewController 是基于导航的应用程序

标签: iphone uinavigationcontroller addsubview


【解决方案1】:

也许问题在于方法被称为pushViewController 而不是pushToViewController。试试

SecondViewController *secondVC = [SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];
// don't forget release here
[secondVC release];

【讨论】:

  • 嗨。不,那只是错字。我会纠正它。但还有其他想法吗??
【解决方案2】:

如果您使用过基于视图的应用程序,则必须使用此代码。

  SecondViewController *secondVC = [SecondViewController   alloc]initWithNibName:@"SecondViewController" bundle:nil];
   // [self.navigationController pushViewController:secondVC animated:YES];

      [self presentModalViewController:secondVC animated:YES];

如果你想在你的应用程序中使用导航控制器。首先,您必须在您的 appln 中添加导航控制器,然后才能导航视图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-03
    • 2023-03-27
    • 2018-05-26
    • 2017-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多