事後通知を使用しようとしていますが、適切に実装できません。これは私が持っているものです:
ViewControllerOne.m 内
NSLog(@"PostNotification");
[[NSNotificationCenter defaultCenter] postNotificationName:@"Connectivity" object:nil];
ViewControllerTwo.m 内
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Added Obeserver");
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(connectedTo:) name:@"Connectivity" object: nil];
}
-(void)connectedTo:(NSNotification *)notification
{
m_connectivity = @"Connected";
}
connectedTo 関数が呼び出されていないようです。それの訳は:
コードの別の部分:
if ([m_connectivity isEqualToString:@"Connected"])
{
NSLog(@"Connected");
}
else
{
NSLog(@"NotConnected");
}
私の間違いが何であるかわかりません。いくつかのガイダンスが必要です...ありがとう..
編集:
ViewControllerOne.m は、他のビューコントローラーがサブクラス化するクラスです。接続をチェックし、接続されたら、接続されていることを他のviewcontroller(ViewControllerTwo)に通知し、接続に基づいて必要なアクションを実行する必要があります。したがって、接続が変更されると、通知が送信されますが、その時点でビューコントローラーが初期化されていない可能性があります...