@protocol CallBackDelegate; @interface ViewController : UIViewController @property (weak, nonatomic) id<CallBackDelegate> delegate; @end @protocol CallBackDelegate <NSObject> - (void)showArrayWithDelegate:(NSArray *)array; @end
- (IBAction)delegateCallBack { NSDictionary *dict = @{@"array": @[@"Chelsea", @"MUFC", @"Real Madrid"]}; NSArray *array = dict[@"array"]; [self.delegate showArrayWithDelegate:array]; }
- (void)showArrayWithDelegate:(NSArray *)array { _outputLabel.text = array[2]; }
- (IBAction)callBack { NSDictionary *dict = @{@"array": @[@"Chelsea", @"MUFC", @"Real Madrid"]}; NSArray *array = dict[@"array"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"OutputArrayNotification" object:array]; }
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(outputWithNote:) name:@"OutputArrayNotification" object:nil]; } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; [[NSNotificationCenter defaultCenter] removeObserver:self name:@"OutputArrayNotification" object:nil]; }
- (void)outputWithNote:(NSNotification *)aNotification { NSArray *receiveArray = [aNotification object]; _outputLabel.text = receiveArray[0]; }
- (void)showArrayUsingBlock:(Arr_Block)block { NSDictionary *dict = @{@"array": @[@"Chelsea", @"MUFC", @"Real Madrid"]}; NSArray *array = dict[@"array"]; block(array); }
- (IBAction)blockCallBack { [self showArrayUsingBlock:^(NSArray *array) { _outputLabel.text = array[1]; }]; }