我有一个UIViewController
用户点击一个按钮然后他们去另一个UIViewController
做一些图像处理的地方。一旦图像被操纵,我想要一个NSNotification
.
我突出的问题是,当用户完成裁剪图像时,我没有收到NSNotification
第一个消息...我涵盖了所有理由并将通知处理方法放入, , ...UIViewController
- (void) finishCropping
viewDidLoad
viewWillAppear
viewWillAppear
我不明白为什么我没有收到通知?这应该很简单
如果我注释掉它的工作原理......[[NSNotificationCenter defaultCenter] removeObserver:self];
但从viewDidDisappear
理论上讲......如果我重新设置通知处理程序,它们应该在 3 种可用方法中的任何一种中再次调用?
第一个 UIViewController 和 NSNotification 接收器
- (void) addNewPictureFromLibrary {
[self.view endEditing:YES];
imageCroppingViewController* popupController = [self.storyboard instantiateViewControllerWithIdentifier:@"imageCroppingView2"];
[self.navigationController pushViewController:popupController animated:YES];
}
- (void) viewDidDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void) viewDidLoad {
[self notifications];
}
- (void) viewWillAppear:(BOOL)animated {
[self notifications];
}
- (void) viewDidAppear:(BOOL)animated {
[self notifications];
}
- (void) notifications {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(imageCroppingView:)
name:@"imageCroppingView"
object:nil];
}
- (void) imageCroppingView:(NSNotification *) notification {
NSLog(@"imageCroppingView IN HERE");
}
发件人 UIViewController
- (void) finishCropping {
float zoomScale = 1.0 / [scrollView zoomScale];
CGRect visibleRect;
visibleRect.origin.x = scrollView.contentOffset.x * zoomScale;
visibleRect.origin.y = scrollView.contentOffset.y * zoomScale;
visibleRect.size.width = scrollView.bounds.size.width * zoomScale;
visibleRect.size.height = scrollView.bounds.size.height * zoomScale;
UIImage *cropped = imageFromView(imageView.image, &visibleRect);
NSDictionary *dictionary = @{@"image":cropped};
self.navigationController.navigationBar.hidden = NO;
[self.navigationController popToRootViewControllerAnimated:TRUE];
[[NSNotificationCenter defaultCenter]
postNotificationName:@"imageCroppingView"
object:nil
userInfo:dictionary];
}