Я изучаю NSNotificationCenter. Вот мой кодПередача ivar trough NSNotificationCenter
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");
}
}
Я думаю, что я undestand, как работает NSNotification, но как пройти через Ивар NSNotification?
Допустим, Osender.h этот код
Osender.h
@interface Osender : NSObject
{
IBOutlet UITextField *txt;
}
@property (nonatopic, copy) IBOutlet (UITextField *) *txt
Как уведомить reciveTestNotification и передавать данные на него, когда тип пользователя или изменить что-то на TXT?
Я получаю семантическую проблему: метод '-hasObjectForKey:' не найден. Думаю, это потому, что уведомление не отвечает на этот метод? – nedich
Исправлено. Виноват. Вам не нужно проверять, существует ли объект в 'NSDictionary'. Он просто возвращает 'nil', если нет объекта. –