I have a NavigationController that present a view (ShoppingController) with a button which one I call a ModalViewController :
AddProductController *maView = [[AddProductController alloc] init];
maView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:maView animated:YES];
When I want exchange data from my modal view to his parent, I have an error because [self parentViewController] refer to my NavigationController and not my ShoppingController.
How can I send data from my ModalView AddProductController to my caller ShoppingController ?
You could use the delegate pattern.
In your AddProductController class, when handling the button tap, you can then send a message to its delegate, which you set as your ShoppingController.
So, in AddProductController:
Then, in ShoppingController (and don’t forget to release maView):
If you want to get fancy, you can make receiveData: part of a protocol. Then, your ShoppingController can implement the protocol, and instead of checking with
[self.delegate respondsToSelector:@selector(x)], you check that[self.delegate conformsToProtocol:@protocol(y)].