简体   繁体   English

视图控制器没有被推送到堆栈

[英]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.

相关问题 在推送到堆栈的新viewController中更新NSMutableArray - Updating a NSMutableArray in new viewController that's pushed onto the stack 在iOS6中,将ViewController推入堆栈时强制将ViewController强制为特定的interfaceOrientation - In iOS6, trouble forcing ViewController to certain interfaceOrientation when pushed on stack 检查Viewcontroller何时被推送 - Detect when Viewcontroller was Pushed 将视图控制器的父级推送到具有多个 UINavigationController 的 UITabBarController 中的 UINavigationController 堆栈上 - Getting Parent of A View Controller Pushed on a UINavigationController stack in a UITabBarController with Multiple UINavigationControllers ViewController堆栈 - ViewController Stack 为什么我得到的ViewController实例与推送到navigationController的实例不同? - Why am I getting a different instance of a ViewController than the one I pushed onto the navigationController? 由NavigationController推送时,ViewController +4的零售额 - retaincount of ViewController +4 when pushed by NavigationController 告诉ViewController推送了DetailViewController - Tell which ViewController pushed the DetailViewController 从推送的ViewController到rootViewController的信息 - Information from pushed viewController to rootViewController 指定由segue推送哪个viewController? - Specify which viewController is pushed by segue?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM