Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: Category with property + "unrecognized selector sent to instance" exception

First of all I have seen that there are many questions about "unrecognized selector sent to instance" issue.
I have seen few but saw nothing about accessing a defined in category property...

I have a category on UILabel with a property.
The getter and the setter are defined.
Actually I have the same property in 2 different categories (for 2 different classes: UIButton and UILabel).
The problem is that I can access this property for UIButton but not for UILabel.
Once I try to access any method/property in UILabel(text) category it drops the "-[UILabel test]: unrecognized selector sent to instance 0x4e539f0" exception.

Both categories files are imported.

I have no idea what is the problem.

Here is some code:

// UILabel+text.h
@interface UILabel (text)
  - (void)test;
@end

// UILabel+text.m
@implementation UILabel (text)
- (void)test {
  NSLog(@"test");
}
@end

// UIButton+text.h
@interface UIButton (text)
  - (void)test;
@end

// UIButton+text.m
@implementation UIButton (text)
- (void)test {
  NSLog(@"test");// works   
}
@end

// Usage (in UIViewController class) - both elements are defined in XIB
[self.button test];// works
[self.label test];// exception

Any help will be appreciated.
I don't have a clue for possible problem...

Thank you.

Michael.

like image 562
Michael Kessler Avatar asked Mar 03 '11 11:03

Michael Kessler


1 Answers

Are you using a static library? If so, add all_load to Other Linker Flags.

Are you sure "UILabel+text.m" is in the target?

like image 189
Steven Kramer Avatar answered Oct 15 '22 14:10

Steven Kramer