Target/action 设计模式

RootView.m 中

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];button.frame = CGRectMake(100, 100, 100, 40);[button setTitle:@”Target” forState:UIControlStateNormal];[self addSubview:button];// addTarget:self.controller 原来是 self// 方法 RootViewButtonDidClicked 在 ViewController.m 里面实现[button addTarget:self.controller action:@selector(RootViewButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];

RootView.h 中

设置属性

@property (nonatomic, assign)UIViewController *controller;

ViewController.m

// 点击事件- (void)RootViewButtonDidClicked:(UIButton *)sender{NSLog(@”hello”);}- (void)viewDidLoad {[super viewDidLoad];= self;}

版权声明:本文为博主原创文章,未经博主允许不得转载。

,每天告诉自己一次,『我真的很不错』

Target/action 设计模式

相关文章:

你感兴趣的文章:

标签云: