Reputation: 5259
I am using push notifications in my code and whenever a notification comes, I want to update the value of a label in another ViewController.
My code in AppDelegate is:
- (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];
}
then in my other view controller I have this code:
@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"]];
}
the log is printed correctly but when I manually go into that screen I see the default value, like the label is not updated at all. What should I do?
Upvotes: 0
Views: 212
Reputation: 500
You have to make sure that when you "manually go" to MyDealsViewController
, whatever how you do it, it got to be the same instance of MyDealsViewController
wich has been called receiveCode
. Otherwise it's going to init with it's default values.
Upvotes: 1