uilabel - NSRangeException Out of Bounds error -
i setting attributed text of label, , getting strange error: terminating app due uncaught exception 'nsrangeexception', reason: 'nsmutablerlearray replaceobjectsinrange:withobject:length:: out of bounds'. have never seen error before, not sure how fix it. here code causing crash:
if ([cell.wavetextlabel respondstoselector:@selector(setattributedtext:)]) { const cgfloat fontsize = 16.0f; //define attributes uifont *boldfont = [uifont fontwithname:@"helveticaneue-medium" size:fontsize]; // create 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 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 label text [cell.wavetextlabel setattributedtext:attributedstring]; }
i set exception breakpoint, , crashing on line [attributedstring setattributes:attrs range:namerange];
know how can fix this?
Comments
Post a Comment