4
votes

I created my own class for PopoverController (Without subclassing UIPopoverController) to present ViewControllers in the way i want.

CustomPopoverController is NOT a UIViewController, instead it has an ivar called "contentViewController" which is the VC that will actually be displayed.

I implemented my own "dismissPopoverAnimated:" to dismiss my custom popover when the user tap anywhere outside the contentViewController's frame:

-(void) dismissPopoverAnimated : (BOOL) animated
{
     // dismissalView is the view that intercept the taps outside.
    [self.dismissalView removeFromSuperview];
    self.dismissalView = nil;
    if (animated)
    {
        CGRect newFrame = self.view.frame;
        // When in landscape Mode the width of the screen is actually the "height"
        newFrame.origin.y = [UIScreen mainScreen].bounds.size.width;

        [UIView animateWithDuration:0.5 
                         animations:^{self.view.frame = newFrame;} 
         completion: ^(BOOL finished) {if(finished) [self.contentViewController.view removeFromSuperview];}];
    }
    else 
    {
        [self.contentViewController.view removeFromSuperview];
    }
    isPresented = NO;
    [self.delegate customPopoverDidDismissPopover:self];
}

The problem is, that even though removeFromSuperView is called in any case - animated or not, the contentViewController never receives either viewWillDisappear, viewDidDisappear or even viewDidUnload when i'm releasing the contentViewController;

Does anyone have an idea why? Or even better throw some light on the chain of viewWill.../viewDid... method and when they supposed to be called.

1
If CustomPopoverController is NOT a UIViewController.. then what is CustomPopoverController? self.contentViewController.view removeFromSuperview]; I think will call the viewWillDisappear in ContentViewControllervisakh7
@7KV7 - CustomPopoverController is my own class, derived directly from NSObject. And my problem is viewWillDisappear is NOT called in contentViewController as expected. That's exactly what i'm trying to achieve.Avi Shukron

1 Answers

10
votes

When you add subview or remove subview by the methods of UIView, it never cause owned UIViewController call viewWillAppear, viewDidAppear, viewWillDisappear, and viewDidDisapper. Only those viewController managed by the method of UINavigationController, like pushViewController:animated: or popViewControllerAnimated:, or presentModelViewController:aniamted: ... etc. They will notify about the status is changing for the view of controller.