私はiPhoneの初心者で、以下に示すランタイムエラーが発生しました。getColor メソッドでオブジェクトを渡すと、「textView.textColor=[self getColor:appDelegate.pickcolor];」エラーが発生します
キャッチされない例外 'NSRangeException' が原因でアプリを終了しています。理由: '-[__NSCFConstantString substringWithRange:]: 範囲またはインデックスが範囲外です'
- (UIColor *) getColor: (NSString *) hexColor
{
//NSLog(@"Calling Getcolor..");
unsigned int red, green, blue;
NSRange range;
range.length = 2;
range.location = 0;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red];
//NSLog(@"\n\tRed :%d\n",red);
range.location = 2;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&green];
//NSLog(@"\n\tgreen :%d\n",green);
range.location = 4;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&blue];
//NSLog(@"\n\tblue :%d\n",blue);
return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green/255.0f) blue:(float)(blue/255.0f) alpha:1.0f];
}
提案と解決策を教えてください