IOS 의 target action 컨트롤 구현

1415 단어 IOStargetaction
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 컨트롤 의 실현 입 니 다.궁금 한 점 이 있 으 시 면 댓 글 을 남기 거나 본 사이트 커 뮤 니 티 에 가서 토론 을 하 십시오.읽 어 주 셔 서 감사합니다. 도움 이 되 셨 으 면 좋 겠 습 니 다.본 사이트 에 대한 지지 에 감 사 드 립 니 다!

좋은 웹페이지 즐겨찾기