简体   繁体   中英

Viewcontroller not getting pushed to stack

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.

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.

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM