IOS开发中目标动作的控制操作
来源:爱站网时间:2020-10-27编辑:网友分享
Target-action贯穿于IOS开发中,但对于初学者来说,这种模式仍然令人非常的困惑,爱站技术频道小编主要为大家介绍了IOS开发中目标动作的控制操作,需要的朋友可以进入下文学习。
Target-action贯穿于IOS开发中,但对于初学者来说,这种模式仍然令人非常的困惑,爱站技术频道小编主要为大家介绍了IOS开发中目标动作的控制操作,需要的朋友可以进入下文学习。
IOS中的target action控件的实现
实现代码:
#import@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开发中目标动作的控制操作吧,最后建议大家都收藏js.aizhan.com,这里不仅有专业的知识,还有专业的团队为你进行筛选实用的知识。