欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > 内容正文

UI_Target/action 设计模式,ui_targetaction

来源: 开发者 投稿于  被查看 11942 次 评论:243

UI_Target/action 设计模式,ui_targetaction


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.rootView.controller = self;

}

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

相关频道:

用户评论