Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I call the original function from the overloaded function in a category?

In Objective-C, I have a category for a class:

@interface UILabel(CustomInit)

- (id)initWithCoder:(NSCoder *)coder;

@end

What I'm doing is writing a custom init function that does some extra stuff, and what I'd like to do, is in this custom init function, call the UILabel's base initWithCoder. Is this possible? How so?

EDIT

Thanks. Ok, so my plans moot. Can't just overload initWithCoder. Is there a way to achieve the same functionality (where all UILabels get this added initialization step) without overloading initWithCoder? Or perhaps is there sample code for the UILabel's initWithCoder that I can just rewrite with the added code?

EDIT

Ok, so to be clear about what I'm trying:

Can I embed a custom font in an iPhone application?

has an answer in which someone manually adds a custom font on the iphone using the private GraphicServices function GSFontAddFromFile. I tried this code and it worked great for manually setting the font of a label. However, if you try setting the font in Interface Builder, it doesn't load properly, it just drops down to the system font. What I wanted to do was load the font manually and set the label's font automatically with the chosen font in IB. This way I don't need to make an outlet for every label I put down. I also don't have to write a ridiculous label subclass (which was also suggested in that thread and does a large amount of custom drawing) which I found rather grotesque. Now I could still make a subclass for all my labels, but then there's the case of embedded labels in other UI objects, ie UIButtons. I'd like the embedded labels to also not be broken.

Any suggestions would be great. Thanks.

like image 616
kidnamedlox Avatar asked Dec 07 '22 06:12

kidnamedlox


1 Answers

From the Mac OS X Reference Library:

When a category overrides an inherited method, the method in the category can, as usual, invoke the inherited implementation via a message to super. However, if a category overrides a method that already existed in the category's class, there is no way to invoke the original implementation.

like image 181
Ferruccio Avatar answered Jan 18 '23 11:01

Ferruccio