I have a class which can be accessed from all other pages just like facebook chat head bubble.Its a cart in my application.Items to the cart could be added from different views. HAve tried with NSNotification and is not working.The array inside the cart view is gettig as null.Any help?What i tried is:
-(IBAction)addToCart:(id)sender{
NSMutableArray *itemToCart=[[NSMutableArray alloc]init];
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObject:gearImgView.image forKey:@"equipImage"];
[dict setObject:nameLbl.text forKey:@"name"];
[dict setObject:priceLbl.text forKey:@"price"];
[dict setObject:self.shopifyIDString forKey:@"shopifyID"];
[itemToCart addObject:dict];
[[NSNotificationCenter defaultCenter] postNotificationName:@"equipmentSelected" object:nil userInfo:dict];
}
And in the cart view,
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadEquipmentview:) name:@"equipmentSelected" object:nil];
[super viewDidLoad];
}
-(void)loadEquipmentview:(NSNotification *)notification{
NSDictionary *dict = [notification userInfo];
NSString *shopifyID = [dict objectForKey:@"shopifyID"];
NSLog(@"%@",dict);
}
If you aren't using ARC, you might want to change the following line,
To;