博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UI_Target/action 设计模式
阅读量:6954 次
发布时间:2019-06-27

本文共 713 字,大约阅读时间需要 2 分钟。

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;}

转载地址:http://rlvil.baihongyu.com/

你可能感兴趣的文章