Objective C的二传手在超调用,而不是子类
问题描述:
我想继承的UILabel所以二传手的setText检查空,以避免这种情况,如果所提供的参数是NSNULL: [NSNull isEqualToString:]:无法识别的选择发送到实例Objective C的二传手在超调用,而不是子类
代码如下。我在调试器台阶的贯通,并没有进入新的二传手我把它叫做是:
[someSubClassLabel setText:someValueWhichMayBeNull];
其中someSubClassLabel是UILabelWithNULLHandler。
在.H#import <UIKit/UIKit.h>
@interface UILabelWithNULLHandler : UILabel
- (void) setText:(NSString *) newText;
@end
定义在.M方法
:
- (void) setText:(NSString *) newText
{
if(![newText isKindOfClass:[NSNull class]])
{
super.text = newText;
}
else
{
super.text = @"";
}
}
编辑: 我想我可以添加代码来处理为零,但暂时,我我正在处理从NSDictionary中提取的NSNUll。
答
@Hick Licks是对的。我的故事板中仍然有UILabel。需要在Custom Class中的Identity Inspector中设置新的类名。
你确定是KindOfClass吗?为什么不: if(newText){//做某事 ... – 2013-02-25 11:54:45
而'someSubClassLabel'是'UILabelWithNULLHandler'的一个实例? – *foe 2013-02-25 11:55:34
你确定'someSubClassLabel'的类型是你的新'UILabelWithNULLHandler'吗? – 2013-02-25 11:55:47