Edit
According to Apple's documentation, you SHOULD discard the viewcontroller from the parent (view) viewcontroller: http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid7TP445 CH111-SW14
βWhen it comes time to reject the presented view controller, the preferred approach is to allow the view manager to reject it. In other words, when possible, the same view controller that the view controller introduced should also take responsibility for dismissing this.β .
Also, can you clarify which upcoming controllers represent which and how much overlap. from apple docs:
"If you consecutively represent multiple view controllers and thus create a stack of presented view controllers, calling this method on the view controller below in the stack rejects its immediate child view controller and all view controllers above that child in the stack. When this happens, only the top the view opens in an animated view, and any intermediate view controllers are simply removed from the stack. using its modal transition style, which may differ from the styles used by other view controllers below on the stack. "
So, if you think this may have anything to do with the delegation methods coming from your web browser, you probably should probably unsubscribe the view from the delegation property / stop viewing the web page from loading in viewWillUnload. and not a retired IBAction, since it won 'must be called.
I edited this to make it more complete / understandable
Before presenting a view, you need to configure your browser view to an instance variable with a strong property. Then set it to zero after rejecting it.
First create a delegate protocol for modals:
@protocol ModalViewDelegate - (void)modalDidDismiss:(UIViewController*)viewController; @end
In your view manager interface view, subscribe to the protocol:
@interface PresentingViewController <ModalViewDelegate> @property (nonatomic,strong) WebBrowser *browserView; @end
In your implementation, when presenting a view:
WebBrowser *browser = [[WebBrowser alloc] initWithURL:URL]; browser.delegate = self self.browserView = browser; [self presentViewController:browser animated:YES completion:NULL];
In the WebBrowser interface:
@interface WebBrowser : ITViewController <UIWebViewDelegate, UIAlertViewDelegate> @property (nonatomic, strong) NSString *URL; @property (nonatomic, weak) IBOutlet UIWebView *webView; @property (nonatomic, weak) IBOutlet UIActivityIndicatorView *spinner; @property (nonatomic, weak) id <ModalViewDelegate> delegate; - (id)initWithURL:(NSString *)URL; - (IBAction)dismissView:(id)sender; @end
In your implementation of WebBrowser:
- (IBAction)dismissView:(id)sender { self.URL = nil; [self.webView stopLoading]; self.webView.delegate = nil; [self.delegate didDismissBrowser:self]; }
And again in the parent view controller:
- (void)didDismissBrowser:(WebBrowser*)browser { if (browser == self.browserView) { [self dismissViewControllerAnimated:YES completion:NULL]; self.browserView = nil; } }