我正在设置标签的属性文本,我收到这个奇怪的错误:由于未捕获的异常'NSRangeException'而终止应用程序,原因:'NSMutableRLEArray replaceObjectsInRange:withObject:length :: Out of bounds'。我之前从未见过这个错误,所以我不确定如何修复它。以下是导致崩溃的代码:
if ([cell.waveTextLabel respondsToSelector:@selector(setAttributedText:)])
{
const CGFloat fontSize = 16.0f;
//define attributes
UIFont *boldFont = [UIFont fontWithName:@"HelveticaNeue-Medium" size:fontSize];
// Create the attributes
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:boldFont, NSFontAttributeName, nil];
NSRange rangeOfIs = [cell.cellWaveObject.waveString rangeOfString:@" is"];
NSLog(@"The range of is: {%lu, %lu}", (unsigned long)rangeOfIs.location, (unsigned long)rangeOfIs.length);
NSRange nameRange = NSMakeRange(0, rangeOfIs.location);
NSLog(@"The range of the name: {%lu, %lu}", (unsigned long)nameRange.location, (unsigned long)nameRange.length);
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:cell.cellWaveObject.waveString];
[attributedString setAttributes:attrs range:nameRange];
//set the label text
[cell.waveTextLabel setAttributedText:attributedString];
}
我设置了一个异常断点,它在[attributedString setAttributes:attrs range:nameRange];
行崩溃了吗?有人知道如何解决这个问题吗?