我有一个继承自
NSAttributedString
这样地:
#import <Foundation/Foundation.h>
@interface Text : NSAttributedString
-(id) initWithString:(NSString*) text andFont:(NSFont*)font andLineHeight:(float) lineHeight andLetterSpacing:(float) letterSpacing;
@end
文本m:
#import "Text.h"
#import <Cocoa/Cocoa.h>
@implementation Text
-(id) initWithString:(NSString*) text andFont:(NSFont*)font andLineHeight:(float) lineHeight andLetterSpacing:(float) letterSpacing
{
NSMutableParagraphStyle* paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setParagraphStyle: [NSParagraphStyle defaultParagraphStyle]];
paragraphStyle.lineHeightMultiple = lineHeight;
NSDictionary* attributes =
@{
NSFontAttributeName: font,
NSKernAttributeName: @(letterSpacing),
NSParagraphStyleAttributeName: paragraphStyle
};
self = [super initWithString:text attributes:attributes];
return self;
}
@end
当我像这样实例化类时:
[[Text alloc] initWithString:@"Test" andFont:welcomeLabelFont andLineHeight:52 andLetterSpacing:0.0f]];
我得到以下例外:
2017-07-17 17:21:15.771610+0300 Test[41403:10128169] -[Text initWithString:attributes:]: unrecognized selector sent to instance 0x600000000f70
选择器在基类中可用,事件ctrl单击它会跳转到
NSAttributedText
班谁能指出我做错了什么?参数不是零指针,调用似乎是合法的。唯一看起来奇怪的是错误有类名
Text
NSAttribute字符串
.