Skip to content

Instantly share code, notes, and snippets.

@olxios
Last active November 29, 2016 13:23
Show Gist options
  • Save olxios/06c3c60c83bd19cb694b3a13a57144b2 to your computer and use it in GitHub Desktop.
Save olxios/06c3c60c83bd19cb694b3a13a57144b2 to your computer and use it in GitHub Desktop.
@implementation TestView
#pragma mark - Observers
- (void)didMoveToWindow
{
if (self.window) // If self.window != nil, it means view was added to the window
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(test:)
name:@"TestNotification"
object:nil];
}
}
- (void)willMoveToWindow:(UIWindow *)newWindow
{
if (newWindow == nil) // if newWindow == nil, it means view was removed from the window
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:@"TestNotification"
object:nil];
}
}
#pragma mark - Actions
- (void)test:(NSNotification *)notification
{
NSLog(@"Test!");
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment