0
처리기 이벤트에 문제가 있습니다. 하나의 NSString 매개 변수로 핸들러를 생성해야합니다. 나는 노력하지만 작동하지 않습니다. 샘플 코드 :매개 변수가있는 이벤트 처리기
@interface Example : NSObject {
id target;
SEL action;
}
- (id)initWithTarget:(id)targetObject action:(SEL)runAction;
- (void)activate;
@end
@implementation Example
- (id)initWithTarget:(id)targetObject action:(SEL)runAction {
if (self = [super init]) {
target = targetObject;
action = runAction;
}
return self;
}
- (void)activate {
[target performSelector:action withObject:self withObject: @"My Message"];
}
@end
@interface ExampleHandler : NSObject {
}
-(void):init;
-(void)myHandler:(NSString *)str;
@end
@implementation ExampleHandler
-(void)init {
[super init];
Example *ex = [[Example alloc] initWithTarget: self action: @selector(myHandler) ];
}
-(void)myHandler:(NSString *)str {
NSLog(str);
}
@end
하나의 매개 변수를 가진 처리기가있는 코드는 어떻게 변경해야합니까?
OP가 @selector (myHandler)를 사용했다는 점도 주목할 가치가 있습니다. 누락 된 콜론은 @selector (myHandler :)이어야합니다. –