IOS中的target action控件的实现
IOS中的targetaction控件的实现
实现代码:
#import@interfaceSample:NSObject{ SELaction; idtarget; } @propertySELaction; @property(assign)idtarget; -(void)addTarget:(id)taction:(SEL)s; -(void)sample_dosomthing; @end
#import"Sample.h"
@implementationSample
@synthesizeaction;
@synthesizetarget;
-(void)dealloc{
target=nil;
[superdealloc];
}
-(void)addTarget:(id)taction:(SEL)s{
self.action=s;
self.target=t;
}
-(void)sample_dosomthing{
[self.targetperformSelector:self.action];
}
@end
这是一个例子,在一个UIViewController里面
-(void)control_dosomthing{
NSLog(@"control_dosomthing");
}
-(void)viewDidLoad{
[superviewDidLoad];
Sample*sample1=[Samplenew];
[sample1addTarget:selfaction:@selector(control_dosomthing)];
}
以上就是IOS中的targetaction控件的实现,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语