0

I am subclassing an UIButton which is going to be present in all of my app's ViewControllers, kinda Navigation Button. I would like just to put it to my VC and apply custom class, without any code in ViewController itself. So, the questions:
1. is it possible?
2. I am using this code now in my UIButton custom class. What is wrong?:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addTarget:self action:@selector(didTouchButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}


- (void)didTouchButton {
    NSLog(@"YEAH, it works, baby!");
}  

UPD: seems that even initWithFrame method is not being called at all.

Richard Topchii
  • 7,075
  • 8
  • 48
  • 115

1 Answers1

0

Loading from the nib I think.The initWithFrame method doesn't work if not called programatically.

Try -awakeFromNib Method

See this question

Community
  • 1
  • 1
Lithu T.V
  • 19,955
  • 12
  • 56
  • 101