I have a UIViewController
where the user clicks a button and then they go onto another UIViewController
to do some image manipulation. Once the image has been manipulated I want a NSNotification
.
My problem as it stands out is that I am not receiving the NSNotification
in the first UIViewController
when the user finished cropping the image - (void) finishCropping
... I covered all my grounds and put the notification handling method in viewDidLoad
, viewWillAppear
, viewWillAppear
...
I dont understand why I am not receiving the notification? This should be quite straight forward
If i comment out the [[NSNotificationCenter defaultCenter] removeObserver:self];
from viewDidDisappear
it works.... but theoretically speaking... if I am re setting the notification handlers, they should be called again in any of the 3 available methods?
First UIViewController & NSNotification Receiver
- (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");
}
Sender 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];
}