I’m study about NSNotificationCenter. Here is my code
Observer.m
//note init method is not complete here
-(id) init
{
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(reciveTestNotification:)
name:@"TestNotification" object:nil];
}
-(void)reciveTestNotification:(NSNotification *)notification
{
if([[notification name] isEqualToString:@"TestNotification"])
{
NSLog(@"Succesfuly received the test notification");
}
}
Osender.m
-(void)reciveTestNotification:(NSNotification *)notification
{
if([[notification name] isEqualToString:@"TestNotification"])
{
NSLog(@"Succesfuly received the test notification");
}
}
I think that I undestand how NSNotification works, but how to pass ivar via NSNotification ?
Lets say Osender.h have this code
Osender.h
@interface Osender : NSObject
{
IBOutlet UITextField *txt;
}
@property (nonatopic, copy) IBOutlet (UITextField *) *txt
How to notify reciveTestNotification and pass data to it when user type or change something on txt ?
NSNotificationclass has a property for additional data that you might want to send with your notification,userInfo.You post it like this:
And get it like this:
Now
textFieldhas the reference to yourUITextField.