视图控制器没有被推入堆栈

发布于 2024-09-04 02:10:45 字数 534 浏览 10 评论 0原文

我对 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 不会被推送到堆栈。

I am fairly new to iPhone. I have a peculiar problem. I am adding a view controller as a subView to the current view. And then I want to push a new view controller from it. The problem is when I try to do pushViewController, it is not responding.

For example, in CurrentViewController I have added NewViewController's view as subView

[self.view addSubView : NewViewController.view]

Now From NewViewController, on the click of a button I am doing the following :

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

Here the secondVC doesn't get pushed to the stack.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

任谁 2024-09-11 02:10:45

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

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

      [self presentModalViewController:secondVC animated:YES];

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

If you have used view based application, You have to use this code.

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

      [self presentModalViewController:secondVC animated:YES];

If you want to use navigation controller in your appln. First you have to add navigation controller in your appln and then only will navigate the view.

念﹏祤嫣 2024-09-11 02:10:45

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

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

Perhaps the problem is that method is called pushViewController not pushToViewController. Try

SecondViewController *secondVC = [SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];
// don't forget release here
[secondVC release];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文