Mahir
Mahir

Reputation: 1684

Can a subclass of UIImageView respond to touch events?

I know others asked similar questions but I checked and their problems isn't the same as mine.

Here is the code from the customImageView

@implementation KeysTest

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
    [self.userInteractionEnabled:YES]; 
 self.image = [UIImage imageNamed:@"whitekey.gif"];
}
return self;
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"test!");
}

For some reason, it doesn't recognize the userInteractionEnabled method. Also, the codeSense feature didn't work for the touchesBegan method.

Upvotes: 0

Views: 432

Answers (1)

DHamrick
DHamrick

Reputation: 8488

I'm not sure that your code sample would compile correctly. But commenter Sam is correct, [self.userInteractionEnabled:YES] is not a proper function. This needs to be changed to

self.userInteractionEnabled = YES;

Upvotes: 1

Related Questions