user392406
user392406

Reputation: 1323

dismissModalViewController isn't working properly

My app is in working condition but for some reason my app goes to viewDidUnload when I receive memory warning while dismissing modal view controller. I've been through all my code and cannot find a reason for this.

In my app there is no UINavigationController.

code for MainView :

-(void) showInfo:(id) sender
{

  PhotoFeatureViewController *photoGalleryViewController = [[PhotoFeatureViewController alloc] initWithNibName:@"PhotoFeatureViewController" bundle:nil];

  photoGalleryViewController.modalPresentationStyle = UIModalPresentationFullScreen;
  photoGalleryViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  [photoGalleryViewController loadPhotogalleryImages:[itemTagArray objectAtIndex:[detailInfoBtn tag]]];


  [self presentModalViewController:photoGalleryViewController animated:YES];
  [photoGalleryViewController release];
}

code for ModalView :

-(IBAction) dismiss
{

  [self.parentViewController dismissModalViewControllerAnimated:YES];

}

Upvotes: 0

Views: 442

Answers (5)

kris
kris

Reputation: 2526

Did you know that the Apple docs recommend using a delegate with a ModalViewController? If you're still having trouble a different approach like this might help:

Basically, you define a delegate property for the view controller that's being presented modally (i.e photoGalleryViewController) and set it to the parent view controller when you create photoGalleryViewController and present it modally. In dismiss{}, you would use the delegate(parent) to call a method that handles dismissModalViewController.

It requires setting up a protocol for photoGalleryViewController and adding the protocol and the delegate method to the parent view controller's definition, but those extra steps aren't much effort and the better design would probably payoff in the long run.

Apple Doc - View Controller Programmers Guide http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW14

advice on setting modal view controllers using delegates: present modal view controller

Upvotes: 0

Vipin
Vipin

Reputation: 4728

you already got the answer:-

[self dismissModalViewControllerAnimated:TRUE];

Upvotes: 0

Nishant B
Nishant B

Reputation: 2907

Add dismiss function inside photoGalleryViewController. And use it like below:

-(IBAction) dismiss {
    [self dismissModalViewControllerAnimated:YES];
}

Upvotes: 1

dks1725
dks1725

Reputation: 1631

Try out this

-(IBAction) dismiss 
{
    [self dismissModalViewControllerAnimated:TRUE];
}

Upvotes: 1

Paul Ardeleanu
Paul Ardeleanu

Reputation: 6700

In dismiss, try:

[self dismissModalViewControllerAnimated:YES];

Upvotes: 1

Related Questions