Jayshree
Jayshree

Reputation: 281

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.

Upvotes: 0

Views: 466

Answers (2)

Pugalmuni
Pugalmuni

Reputation: 9390

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.

Upvotes: 1

RaYell
RaYell

Reputation: 70474

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

Upvotes: 0

Related Questions