I am setting the attributed text of a label, and I am getting this strange error:
Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray replaceObjectsInRange:withObject:length:: Out of bounds'.
I have never seen this error before, so I am not sure how to fix it. Here is the code causing the crash:
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];
}
I set an exception breakpoint, and it is crashing on the line [attributedString setAttributes:attrs range:nameRange];
does anyone know how I can fix this?