![](/img/trans.png)
[英]'NSConcreteMutableAttributedString initWithString:: nil value' when using Google Nearby Messages
[英]Assigning attributedText to UILabel crashes app with 'NSConcreteMutableAttributedString initWithString:: nil value'
这是我的tableViewCell代码的实现,我在这里做的只是从我的MainViewController获取数据并将其分配给两个不同的UILabel。
该问题存在于UILabel * subTitle中,当我使用attributedText分配它以传递所需的行间距时,应用程序在滚动tableView后崩溃。 但是,如果我只是用.text =分配它,它运行正常,没有崩溃。
@property (strong, nonatomic) IBOutlet UILabel *title;
@property (strong, nonatomic) IBOutlet UILabel *subTitle;
- (void)configureWithPosts:(Data *)data {
self.title.text = data.title;
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:data.excerpt];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[attributeString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [attributeString length])];
[paragraphStyle setLineSpacing:3];
self.subTitle.textColor = [UIColor colorWithRed:102.0f/255.0f green:102.0f/255.0f blue:102.0f/255.0f alpha:1.0];
self.subTitle.attributedText = attributeString;
}
谁能告诉我这里我做错了什么?
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSConcreteMutableAttributedString initWithString:: nil value'
我偶然尝试将字体设置为不存在的字体时遇到此错误:
NSMutableAttributedString *selectedString = [[NSMutableAttributedString alloc] initWithString:self.allUsersButton.titleLabel.text];
[selectedString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:1] range:NSMakeRange(0, selectedString.length)];
[selectedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Neue-Bold" size:16.0f]
这里的问题是NSFontAttributeName应该是fontWithName:@"Helvetica-Neue-Bold"
我之前也遇到过这个问题,看起来这是iOS7上UILabel
的一个错误。
我转而使用TTTAttributedLabel
https://github.com/mattt/TTTAttributedLabel ,我从未见过这样的问题。
错误是表示字符串data.excerpt在行中为nil
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:data.excerpt];
我猜你真的想要data.title 。 但这只是猜测你的其余代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.