Search code examples
objective-coverridingnsnull

Objective C setter in superclass called instead of subclass


I am trying to subclass UILabel so the setter setText check for null to avoid this if the supplied parameter is a NSNULL: [NSNull isEqualToString:]: unrecognized selector sent to instance

The code is as below. I stepped through in a debugger and it didn't go into the new setter which I called by:

    [someSubClassLabel setText:someValueWhichMayBeNull];

where someSubClassLabel is a UILabelWithNULLHandler.

in the .h

#import <UIKit/UIKit.h>
@interface UILabelWithNULLHandler : UILabel
- (void) setText:(NSString *) newText;
@end

Defined the method in the .m:

- (void) setText:(NSString *) newText
{
    if(![newText isKindOfClass:[NSNull class]])
    {
        super.text = newText;
    }
    else
    {
        super.text = @"";
    }
}

Edit: I suppose I can add code to handle nil, but for the time being, I am dealing with NSNUll which I pulled from a NSDictionary.


Solution

  • @Hot Licks was right. I still have a UILabel in my storyboard. Need to set the new class name in the Identity Inspector under Custom Class.