首页 > 其他 > 详细

UI_Target/action 设计模式

时间:2015-07-04 11:11:16      阅读:205      评论:0      收藏:0      [点我收藏+]

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;

}

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

UI_Target/action 设计模式

原文:http://blog.csdn.net/yadong_zhao/article/details/46753779

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!