martinjuhasz / MJPopupViewController

A UIViewController Category to display a ViewController as a popup with different transition effects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

some times crashed when dismiss

adad184 opened this issue · comments

- (void)fadeViewOut:(UIView*)popupView sourceView:(UIView*)sourceView overlayView:(UIView*)overlayView
{
    [UIView animateWithDuration:kPopupModalAnimationDuration animations:^{
        [self.mj_popupViewController viewWillDisappear:NO];
        self.mj_popupBackgroundView.alpha = 0.0f;
        popupView.alpha = 0.0f;
    } completion:^(BOOL finished) {
        [popupView removeFromSuperview];
        [overlayView removeFromSuperview];
        [self.mj_popupViewController viewDidDisappear:NO];
        self.mj_popupViewController = nil;
    }];
}

it shows on line

[popupView removeFromSuperview];

it happens occasionally :(

the problem may be here

- (void)dismissPopupViewControllerWithanimationType:(MJPopupViewAnimation)animationType
{

    UIView *sourceView = [self topView];
    UIView *popupView = [sourceView viewWithTag:kMJPopupViewTag];
    UIView *overlayView = [sourceView viewWithTag:kMJOverlayViewTag];

    switch (animationType) {
        case MJPopupViewAnimationSlideBottomTop:
        case MJPopupViewAnimationSlideBottomBottom:
        case MJPopupViewAnimationSlideTopTop:
        case MJPopupViewAnimationSlideTopBottom:
        case MJPopupViewAnimationSlideLeftLeft:
        case MJPopupViewAnimationSlideLeftRight:
        case MJPopupViewAnimationSlideRightLeft:
        case MJPopupViewAnimationSlideRightRight:
            [self slideViewOut:popupView sourceView:sourceView overlayView:overlayView withAnimationType:animationType];
            break;

        default:
            [self fadeViewOut:popupView sourceView:sourceView overlayView:overlayView];
            break;
    }
//    self.mj_popupViewController = nil;
}

the last line, self.mj_popupViewController may be released before animation is done?

Looks like you're right. This line isn't necessary, because self.mj_popupViewController is set to nil after animation finished. And removing of this line solves the problem.