Jon*_*onN 0 properties subclass objective-c uilabel ios
我是一位经验丰富的C++程序员,试图创建我的第一个UILabel的Objective-C子类,并添加了只读属性
// UINumericlabel.h
@interface UINumericLabel : UILabel
// Returns true if the numeric display contains a decimal point
@property (readonly,nonatomic) BOOL hasDecimalPoint;
@end
Run Code Online (Sandbox Code Playgroud)
// 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
Run Code Online (Sandbox Code Playgroud)
当我尝试为实例化的UINumericLabel引用hasDecimalPoint属性时,我得到一个带有错误
2012-02-20 18:25:56.289 Calculator[10380:207] -[UILabel hasDecimalPoint]: unrecognized选择器的中止
发送到实例0x684c5c0
在调试器中,它将我的UINumericLabel属性声明显示为UILabel*我是否需要在UINumericLabel子类中覆盖UILabel的(id)init?我怎么做?
#import "UINumericLabel.h"
@interface CalculatorViewController : UIViewController <ADBannerViewDelegate>
@property (weak, nonatomic) IBOutlet UINumericLabel *display0;
@end
Run Code Online (Sandbox Code Playgroud)
当我将鼠标悬停在调试器中的display0P上时,它表示它是UILabel*而不是UINumericLabel*
UINumericLabel*display0P = self.display0;
在Interface Builder中,选择标签,然后打开Identity Inspector.在文本字段"类"中它可能会说UILabel.把它改成你的新子类,UINumericLabel.
| 归档时间: |
|
| 查看次数: |
1244 次 |
| 最近记录: |