Ошибка NSRangeException Out of Bounds - программирование
Подтвердить что ты не робот

Ошибка NSRangeException Out of Bounds

Я устанавливаю атрибутный текст метки, и я получаю эту странную ошибку: завершение приложения из-за неотображенного исключения "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]; Кто-нибудь знает, как я могу это исправить?

4b9b3361