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控件的實現,如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答