tags:

views:

79

answers:

1

For example I want to overwrite from UIButton:

+ (id)buttonWithType:(UIButtonType)buttonType

So I would do:

+ (id)buttonWithType:(UIButtonType)buttonType {
   UIButton *button = [UIButton buttonWithType:buttonType];
   if (button != nil) {
      // do own config stuff ...
   }
   return button;
}

is that the right way? Or did I miss something? (yeah, I have been overwriting thousands of instance methods, but never class methods ;) )

+1  A: 

So you got recursion.

Unfortunately you can not create a button with the specified type using a method other than buttonWithType. If you need to somehow initialize button after creation, you can make your own static method:

+(id)buttonWithTypeEx:(UIButtonType)buttonType {
   UIButton *button = [UIButton buttonWithType:buttonType];
   if (button != nil) {
      // do own config
   }
   return button;
}
Victor