IOS中的target action控件的实现

Penny ·
更新时间:2024-09-20
· 662 次阅读

IOS中的target action控件的实现

实现代码:

#import <Foundation/Foundation.h> @interface Sample : NSObject { SEL action; id target; } @property SEL action; @property (assign) id target; -(void)addTarget:(id) t action:(SEL) s; -(void)sample_dosomthing; @end #import "Sample.h" @implementation Sample @synthesize action; @synthesize target; -(void)dealloc{ target = nil; [super dealloc]; } -(void)addTarget:(id) t action:(SEL) s{ self.action = s; self.target = t; } -(void)sample_dosomthing{ [self.target performSelector:self.action]; } @end

这是一个例子,在一个UIViewController里面

-(void)control_dosomthing{ NSLog(@"control_dosomthing"); } - (void)viewDidLoad { [super viewDidLoad]; Sample *sample1 = [Sample new]; [sample1 addTarget:self action:@selector(control_dosomthing)]; }

以上就是IOS中的target action控件的实现,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

您可能感兴趣的文章:iOS触摸事件UITouch应用详解iOS二维码的生成代码iOS获取某个日期后n个月的日期iOS如何让tableview支持不同种类的cell详解iOS实现支持小数的星星评分组件实例代码React Native第三方平台分享的实例(Android,IOS双平台)IOS 开发之ObjectiveC的变量类型的字符代表



action IOS target

需要 登录 后方可回复, 如果你还没有账号请 注册新账号