Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

提示弹窗销毁时导致监听被提前释放 #97

Open
lilangkit opened this issue Apr 20, 2021 · 5 comments
Open

提示弹窗销毁时导致监听被提前释放 #97

lilangkit opened this issue Apr 20, 2021 · 5 comments

Comments

@lilangkit
Copy link

  • (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
    {
    for (UIViewController *childVC in self.childViewControllers) {
    if ([childVC respondsToSelector:@selector(viewDidDealloc)]) {
    [childVC performSelector:@selector(viewDidDealloc)];
    }
    }
    [super dismissViewControllerAnimated:flag completion:completion];
    }

  • (void)viewDidDealloc
    {
    LFImagePickerController *imagePickerVc = (LFImagePickerController *)self.navigationController;
    if (imagePickerVc.syncAlbum) {
    [[PHPhotoLibrary sharedPhotoLibrary] unregisterChangeObserver:self]; //移除监听者
    }
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    }

  • (void)dealloc
    {

}

@lincf0912
Copy link
Owner

lincf0912 commented Apr 21, 2021 via email

@lilangkit
Copy link
Author

再次拍摄后,列表就监听不到相册变化了呀,就显示不出来了呀,就虽然选中了,但是看不见。

@lincf0912
Copy link
Owner

lincf0912 commented Apr 26, 2021 via email

@lilangkit
Copy link
Author

LFImagePickerController(UINavigationController)上弹出的 UIAlertController 在销毁时也触发了 LFImagePickerController 的 dismissViewControllerAnimated:completion哦,彩蛋不。而且 dismiss 只是代表暂时不显示,不代表销毁了呀。

@lincf0912
Copy link
Owner

lincf0912 commented Jun 24, 2021

久等了。暂时这样解决。

- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
    /**
     弹出的 UIAlertController 在销毁时也触发了 dismissViewControllerAnimated:completion
     防止弹出的Controller 调用 self.presentingViewController 来销毁,这里判断没有presentedViewController来解决。
     */
    if ([self presentedViewController] == nil) {
        for (UIViewController *childVC in self.childViewControllers) {
            if ([childVC respondsToSelector:@selector(viewDidDealloc)]) {
                [childVC performSelector:@selector(viewDidDealloc)];
            }
        }        
    }
    [super dismissViewControllerAnimated:flag completion:completion];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants