Я опытный программист на C ++, пытающийся создать свой первый подкласс Objective-C UILabel с добавленным свойством только для чтения
// UINumericlabel.h
@interface UINumericLabel : UILabel
// Returns true if the numeric display contains a decimal point
@property (readonly,nonatomic) BOOL hasDecimalPoint;
@end
// UINumericLabel.m
#import "UINumericLabel.h"
@implementation UINumericLabel
// Returns true if the numeric display contains a decimal point
- (BOOL) hasDecimalPoint;
{
return [self.text rangeOfString:(@".")].location != NSNotFound;
}
@end
Когда я пытаюсь сослаться на свойство hasDecimalPoint для созданного экземпляра UINumericLabel, я получаю прерывание с ошибкой
2012-02-20 18:25:56.289 Calculator[10380:207] -[UILabel hasDecimalPoint]: unrecognized
селектор отправлен на экземпляр 0x684c5c0
В отладчике он показывает мое объявление свойства UINumericLabel как UILabel *
Нужно ли переопределить (id) init для UILabel в моем подклассе UINumericLabel? Как мне это сделать?
#import "UINumericLabel.h"
@interface CalculatorViewController : UIViewController <ADBannerViewDelegate>
@property (weak, nonatomic) IBOutlet UINumericLabel *display0;
@end
Когда я нахожу курсор мыши на display0P в отладчике, он говорит, что это UILabel *, а не UINumericLabel *
UINumericLabel * display0P = self.display0;