Delegation
You implement the protocol on your View Controller
In Controller.h
:
@class Controller;
@protocol ControllerDelegate <NSObject>
- (void)sendFrom:(Controller *)controller
image:(UIImage *)image;
@end
@interface Controller : UIViewController
@property (weak, nonatomic) NSObject <ControllerDelegate> * delegate;
@end
In Controller.m
when you want send the image:
[self.delegate sendFrom:self
image: self.image];
After on your Detail View Controller
, don't forget to assign it as delegate of the Controller
. And to implement the ControllerDelegate
protocol. To do that:
In your DetailController.h
implement the protocol. You can do that on your .m as well.
#import "Controller.h"
@interface DetailController : UIViewController <ControllerDelegate>
You keep a reference of the Controller
in The Detail Controller
@property (nonatomic, strong) ViewController *controller;
And assign its delegate
in the viewDidLoad
of the Detail Controller
. For example:
-(void)viewDidLoad:(BOOL)animated{
[super viewDidLoad:animated];
self.controller.delegate = self;
}
Don't forget to implement the protocol method
in your Detail View. Here you receive the image you passed from Controller and you save it in your Detail Controller
UIImage
property:
- (void)sendFrom:(Controller *)controller
image:(UIImage *)image{
self.image = image;
}