Nag_iphone
Nag_iphone

Reputation: 967

Dismiss / Present Modal View Controller - again viewdidLoad is calling

I have faced one strange problem, when I click on the below button informationBtn_clicked. InformationView is coming.

MainView

-(IBAction)informationBtn_clicked:(id)sender{
       InformationView  *obj_Info=[[InformationView alloc] initWithNibName:@"InformationView" bundle:nil];
       UINavigationController *navigationObj = [[UINavigationController alloc] initWithRootViewController:obj_Info];
       [self.navigationController presentModalViewController:navigationObj animated:YES];
}

NextView

After below back btn clicked dismis the view controller;

-(void)btnBackClicked:(id)sender{
    [self dismissModalViewControllerAnimated:YES];
}

Here, my problem is when I dismiss the NextView, again calling main view the viewDidLoad method. My project is running in iOS 5, I am using ARC.

I am checking one way that is the Release the obj_Info but after result the same plz Help Me my English is very poor try to understand me.

Upvotes: 1

Views: 1906

Answers (2)

sch
sch

Reputation: 27506

The problem is that in the line:

UINavigationController *navigationObj = [[UINavigationController alloc] initWithRootViewController:obj_Info];

you initialize the navigation controller with obj_Info as a root view controller. So when you dismiss the modal view controller, the navigation controller shows its root view controller, which happens to be the same as the modal view controller.

Try changing the line I mentioned with:

UINavigationController *navigationObj = [[UINavigationController alloc] init];

Upvotes: 1

mackworth
mackworth

Reputation: 5953

The link he gave you shows there may be a bug in Apple's code that is related to your problem. For now, maybe just workaround (e.g. in viewDidLoad, set a boolean, and then clear it in viewDidUnload; if it's set when you enter viewDidLoad, just return)

Upvotes: 0

Related Questions