Reputation: 14470
I have a UIImageView which I placed in interface builder and set to a custom class I have created SASImageView
. However, when the view is loaded I want to do some setup so I have placed code in awakFromNib
however, this does not seem to be called.
- (void)awakeFromNib {
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapGesture:)];
tap.numberOfTapsRequired = 1;
[self addGestureRecognizer:tap];
}
How would I do some setup for this view in code, after its been loaded from interface builder?
Thanks.
Upvotes: 0
Views: 27
Reputation: 8576
This is something you can easily put in the initWithCoder:
method since you're loading from an XIB file:
-(id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
//Add customizations here
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapGesture:)];
tap.numberOfTapsRequired = 1;
[self addGestureRecognizer:tap];
}
return self;
}
Sidenote: Setting numberOfTapsRequired
to 1
is unnecessary, as that's the default.
Upvotes: 1