I am trying to pass an object from my main view class to another notification receiver in another class.
I want to pass an object named country that loads all cities from a SOAP request to the Main Controller, and I want to send it to the next view.
country = [[Country alloc] init];
Country Header:
@interface Country : NSObject { NSString *name; NSMutableArray *cities; } @property (nonatomic,retain) NSString *name; - (void)addCity:(Cities *)city; - (NSArray *)getCities; - (int)citiesCount; @end
I found a way to transfer data using NSNotificatios using NSDictionary in UserInfo. But is it impossible to send the whole object instead of converting to NSDictionary? Or what is the best way to convey it? I was stuck trying to figure out how to convey objects.
Actually, I got this simple NSNotification in my application.
NSNotification in the implementation of the Main View controller:
//---Call the next View--- DetailViewController *detail = [self.storyboardinstantiateViewControllerWithIdentifier:@"Detail"]; [self.navigationController pushViewController:detail animated:YES]; //--Transfer Data to2View [[NSNotificationCenter defaultCenter] postNotificationName:@"citiesListComplete" object:nil];
NSNotification in the implementation of 2View Controller:
// Check if MSG is RECEIVE - (void)checkMSG:(NSNotification *)note { NSLog(@"Received Notification"); } - (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkMSG:) name:@"citiesListComplete" object:nil];
iphone xcode nsnotificationcenter nsnotifications
Jorge najera t
source share