コードでプッシュ通知を使用していますが、通知が来るたびに、別の ViewController でラベルの値を更新したいと考えています。
AppDelegate の私のコードは次のとおりです。
- (void)addMessageFromRemoteNotification:(NSDictionary*)userInfo updateUI:(BOOL)updateUI
{
NSLog(@"Notification arrived");
//[mydeals setCode1_id:mydeals.code1_id withString:@"123456"];
mydeals=[[MyDealsViewController alloc]init];
NSDictionary* codeDetails=[[NSDictionary alloc] initWithObjectsAndKeys:@"123456",@"Code_id", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"CodeArrived" object:self userInfo:codeDetails];
}
次に、他のView Controllerに次のコードがあります:
@implementation MyDealsViewController
-(id) init
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveCode:)
name:@"CodeArrived"
object:nil];
return self;
}
-(void) receiveCode:(NSNotification*)notification
{
NSLog(@"received Code: %@",notification.userInfo);
self.code1_id.text=[NSString stringWithFormat:@"%@",[[notification userInfo] valueForKey:@"Code_id"]];
}
ログは正しく印刷されますが、手動でその画面に移動すると、ラベルがまったく更新されていないように、デフォルト値が表示されます。私は何をすべきか?