A 修改 B
delegate:这个变量是修改者A(执行者)的变量,指向B
#import <UIKit/UIKit.h> @class MJFoodTypesViewController, MJFoodType; @protocol MJFoodTypesViewControllerDelegate <NSObject> @optional - (void)foodTypesViewController:(MJFoodTypesViewController *)foodTypesVc didSelectedFoodType:(MJFoodType *)type; @end @interface MJFoodTypesViewController : UITableViewController @property (weak, nonatomic) id<MJFoodTypesViewControllerDelegate> delegate; @end
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if ([self.delegate respondsToSelector:@selector(foodTypesViewController:didSelectedFoodType:)]) { MJFoodType *foodType = self.foodTypes[indexPath.row]; [self.delegate foodTypesViewController:self didSelectedFoodType:foodType]; } }
原文:http://www.cnblogs.com/coderMJL/p/5061383.html