[英]Viewcontroller not getting pushed to stack
I am fairly new to iPhone.我对 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.
问题是当我尝试执行 pushViewController 时,它没有响应。
For example, in CurrentViewController I have added NewViewController's view as subView例如,在 CurrentViewController 中,我添加了 NewViewController 的视图作为 subView
[self.view addSubView : NewViewController.view]
Now From NewViewController, on the click of a button I am doing the following :现在从 NewViewController,单击一个按钮,我正在执行以下操作:
SecondViewController *secondVC = [SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];
Here the secondVC doesn't get pushed to the stack.这里 secondVC 不会被推入堆栈。
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.
首先,您必须在 appln 中添加导航控制器,然后才能导航视图。
Perhaps the problem is that method is called pushViewController
not pushToViewController
.也许问题在于该方法被称为
pushViewController
而不是pushToViewController
。 Try尝试
SecondViewController *secondVC = [SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];
// don't forget release here
[secondVC release];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.