2013-10-13 13 views
10

Provo ad assegnare gli attributi a 3 ultimi caratteri della stringa newClock, ovvero @"3:33:23".NSMutableRLEArray objectAtIndex: effectiveRange :: Out of bounds

Tuttavia ho un errore quando costrutto NSRange:

NSMutableAttributedString *mas = [[NSMutableAttributedString alloc]initWithString:newClock]; 
[mas addAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor], 
NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Light" size:12]} 
range:NSMakeRange(newClock.length-3,newClock.length)]; 

risposta

31

NSMakeRange (i, j) crea un intervallo con posizione i e j lunghezza.

Se, ad esempio la dimensione della stringa è 10 e la vostra gamma inizia in 5, e si esegue questa operazione:

NSMakeRange(5,10) 

tuo range va da 5 a 15, così fuori della stringa.

Prova:

NSMakeRange(newClock.length-3,3)]; 
Problemi correlati