小编Alp*_*200的帖子

为什么[NSTextStorage setAttributedString]与NSMutableAttributedString崩溃?

当我运行以下代码时,它会在最后一行崩溃.我不知道为什么.在awakeFromNib中调用此函数.

- (void)setMotdText:(NSString *)text
{
    NSString *boldFontName = [[NSFont boldSystemFontOfSize:12] fontName];
    NSMutableAttributedString *attrstr = [[NSMutableAttributedString alloc] initWithString:text];

    [attrstr beginEditing];

    [attrstr addAttribute:NSFontAttributeName value:boldFontName range:NSMakeRange(0, 16)];

    [attrstr endEditing];

    [self.motdTextView.textStorage setAttributedString:attrstr];
}
Run Code Online (Sandbox Code Playgroud)

我得到这个崩溃日志:

2012-06-22 11:32:22.348 MSM-Plan[20785:403] -[__NSCFConstantString _isDefaultFace]: unrecognized selector sent to instance 0x7fff79b9f380
2012-06-22 11:32:22.349 MSM-Plan[20785:403] An uncaught exception was raised
2012-06-22 11:32:22.349 MSM-Plan[20785:403] -[__NSCFConstantString _isDefaultFace]: unrecognized selector sent to instance 0x7fff79b9f380
2012-06-22 11:32:22.351 MSM-Plan[20785:403] (
    0   CoreFoundation                      0x00007fff8a5bef56 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00007fff8ae19d5e objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff8a64b1be -[NSObject …
Run Code Online (Sandbox Code Playgroud)

macos cocoa objective-c

11
推荐指数
1
解决办法
5506
查看次数

2
推荐指数
1
解决办法
225
查看次数