1 クラスから 3 クラスにデータを渡したい場合は、NSNotification を使用することをお勧めします。このように使えます。
最初の受信クラスで:
@implementation TestClass1
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (id) init
{
self = [super init];
if (!self) return nil;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveNotification1:)
name:@"TestNotification"
object:nil];
return self;
}
- (void) receiveNotification1:(NSNotification *) notification
{
NSLog(@"receive 1");
}
@end
2番目の受信クラスで:
@implementation TestClass2
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (id) init
{
self = [super init];
if (!self) return nil;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveNotification2:)
name:@"TestNotification"
object:nil];
return self;
}
- (void) receiveNotification2:(NSNotification *) notification
{
NSLog(@"receive 2");
}
@end
3番目の受信クラスで:
@implementation TestClass3
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (id) init
{
self = [super init];
if (!self) return nil;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveNotification3:)
name:@"TestNotification"
object:nil];
return self;
}
- (void) receiveNotification3:(NSNotification *) notification
{
NSLog(@"receive 3");
}
@end
投稿クラスで:
- (void) yourMethod
{
[[NSNotificationCenter defaultCenter]
postNotificationName:@"TestNotification"
object:self];
}