I tried to use addTarget to add an event to a UIButton like this
EGOImageButton* image = [[EGOImageButton alloc] initWithPlaceholderImage:[UIImage imageNamed:@"screen.png"]];
[image setImageURL:[NSURL URLWithString:thumbnail]];
[image setFrame:CGRectMake(x, y, self.cellsize, self.cellsize)];
[image setTag: [self.photoIDs count]-1];
[image addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:image];
[image release];
The function definition is this:
-(void)buttonTouched:(id)sender {
NSLog(@"Thumbnail Clicked");
}
This is the code for EGOImageButton init function
- (id)initWithPlaceholderImage:(UIImage*)anImage {
return [self initWithPlaceholderImage:anImage delegate:nil]; }
- (id)initWithPlaceholderImage:(UIImage*)anImage delegate:(id<EGOImageButtonDelegate>)aDelegate {
if((self = [super initWithFrame:CGRectZero])) {
self.placeholderImage = anImage;
self.delegate = aDelegate;
[self setImage:self.placeholderImage forState:UIControlStateNormal];
}
return self;
}
Error is looking like this:
-[NSCFType buttonTouched:]: unrecognized selector sent to instance 0x6c804a0 2012-06-06 01:36:59.061 Photo Collage for Facebook[2416:16103] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType buttonTouched:]: unrecognized selector sent to instance 0x6c804a0' * Call stack at first throw: ( 0 CoreFoundation 0x0046a5a9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x01402313 objc_exception_throw + 44 2 CoreFoundation 0x0046c0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x003db966 __forwarding + 966 4 CoreFoundation 0x003db522 _CF_forwarding_prep_0 + 50