views:

39

answers:

2

Hi !

Why wont this work?

View1 loads View2.
In view2:

- (void) goToView {
  View3 *plainText = [[View3 alloc]
                          initWithNibName:@"View3" bundle:nil];

       [self.navigationController pushViewController:plainText animated: NO];
       [plainText release]; 
  }

- (void)viewDidLoad {
         [self goToView]; 
         [super viewDidLoad];
  }

This will not trigger navigationController to pushView, but if I add a button and setAction (goToView) it works perfectly. What kind of problem do I missing here?

Regards

+1  A: 

Try putting your call to goToView in viewDidAppear instead of viewDidLoad?

- (void) viewDidAppear:(bool)animated {
    [super viewdidAppear:animated];
    [self goToView];
}
deanWombourne
It did the work. Thank you
f0rz
It a common mistake to use `viewDidLoad` instead of `viewDidAppear:`. This causes problems because `viewDidLoad` is only called when a view is first loaded from nib. If you initialize a view it is never called and it is not called every time the view is used subsequently unless the view unloads from memory completely.
TechZen
A: 
[self goToView]; 
[super viewDidLoad];

try interchanging this 2 line.. i.e.

[super viewDidLoad];
[self goToView]; 

I am not sure...

mihirpmehta