UI_Target/action design mode, ui_targetaction
In 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 was originally self // method RootViewButtonDidClicked in ViewController. in m, [button addTarget: self. controller action: @ selector (RootViewButtonDidClicked :) forControlEvents: UIControlEventTouchUpInside];
In RootView. h
Set attributes
@property (nonatomic, assign)UIViewController *controller;
ViewController. m
// Click Event-(void) RootViewButtonDidClicked :( UIButton *) sender {NSLog (@ "hello") ;}- (void) viewDidLoad {[super viewDidLoad]; // set the controller self. rootView. controller = self ;}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.