30

我正在设置标签的属性文本,我收到了这个奇怪的错误:由于未捕获的异常“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];有谁知道我该如何解决这个问题?

4

0 回答 0