开发者

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:@"PhotoFeatureViewCo开发者_如何学Gontroller" 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];

}


In dismiss, try:

[self dismissModalViewControllerAnimated:YES];


Try out this

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


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

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


you already got the answer:-

[self dismissModalViewControllerAnimated:TRUE];


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜