IOS中的target action控件的实现
程序员文章站
2023-12-18 20:24:46
ios中的target action控件的实现
实现代码:
#import
@i...
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控件的实现,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!