Possible Duplicate:
pass NSString variable to other class with NSNotification
My question is : is it possible we can pass data from one to another view controller using postNotificationName and addObserver from notification class in Iphone
You can pass data in the userDictionary element of the API call
NSDictionary *aDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:
anObject, @"objectName",
anotherObject, @"objectId",
nil] autorelease];
[[NSNotificationCenter defaultCenter] postNotificationName:@"AnythingAtAll" object:nil userInfo:aDictionary];
You can retrieve the dictionary from the inbound notification that you observe. Add the observer in advance of posting the notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(anyAction:) name:@"AnythingAtAll" object:nil];
this might be in your init method or a viewDidLoad method
-(void)anyAction:(NSNotification *)anote
{
NSDictionary *dict = [anote userInfo];
AnyClass *objectIWantToTransfer = [dict objectForKey:@"objectName"];
}
note that you should remove your object as an observer in the dealloc method.
[[NSNotificationCenter defaultCenter] removeObserver:self]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With