提示弹窗销毁时导致监听被提前释放
-
(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 {
}
有什么问题吗?
发自我的iPhone
在 2021年4月20日,15:53,李浪 @.***> 写道:
(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion { for (UIViewController childVC in self.childViewControllers) { if ([childVC @.(viewDidDealloc)]) { [childVC @.*(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 {
}
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
再次拍摄后,列表就监听不到相册变化了呀,就显示不出来了呀,就虽然选中了,但是看不见。
不是很明白,触发LFImagePickerController的dismissViewControllerAnimated:completion: 意味着相册已经关闭了。怎么还有拍摄的?
2021年4月22日 上午11:33,李浪 @.***> 写道:
再次拍摄后,列表就监听不到相册变化了呀,就显示不出来了呀,就虽然选中了,但是看不见。
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/lincf0912/LFImagePickerController/issues/97#issuecomment-824512453, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACNOL4TE3XFIEKOPT6K23FLTJ6KKPANCNFSM43HTLUDA.
LFImagePickerController(UINavigationController)上弹出的 UIAlertController 在销毁时也触发了 LFImagePickerController 的 dismissViewControllerAnimated:completion哦,彩蛋不。而且 dismiss 只是代表暂时不显示,不代表销毁了呀。
久等了。暂时这样解决。
- (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];
}