views:

46

answers:

2

hi.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. The am stuck where i was.

EG: In CurrentViewController i have added NewViewController's view as subView

[self.view addSubView : NewViewController.view]

Now From NewViewContrller, 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 doesnt get pushed to the stack. can somebody help me with this. thanks in advance

A: 

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];
RaYell
hi. no that is just typo. i will correct it. but any other idea y this is happening??
Jayshree
A: 

hi Jayshree,

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.

Pugal Devan