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控件的实现,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!