Kex
Kex

Reputation: 8619

Setting up buttons in interface builder but want to call custom init method

I have a custom UIButton class. I have set up the buttons in the interface builder. I have this code:

#import "FriendButton.h"

@implementation FriendButton



-(id)init {

    self = [super init];

    NSLog(@"init called");
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
    [self addGestureRecognizer:longPress];

    return self;

}

It isn't being called though, I have set the class type to FriendButton in the interface builder. Is there a different method I need to use? I know that for custom UITableViewCells one has to use awakeFromNib.

Upvotes: 0

Views: 165

Answers (1)

Phillip Mills
Phillip Mills

Reputation: 31016

From Apple docs:

Objects that conform to the NSCoding protocol (including all subclasses of UIView and UIViewController) are initialized using their initWithCoder: method.

Upvotes: 4

Related Questions