欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

IOS中的target action控件的實(shí)現(xiàn)

 更新時間:2017年08月10日 14:25:53   作者:lizhuang  
這篇文章主要介紹了IOS中的target action控件的實(shí)現(xiàn)的相關(guān)資料,這里提供實(shí)現(xiàn)target action的簡單實(shí)例幫助大家學(xué)習(xí)理解該如何實(shí)現(xiàn),需要的朋友可以參考下

IOS中的target action控件的實(shí)現(xiàn)

實(shí)現(xiàn)代碼:

#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控件的實(shí)現(xiàn),如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論