私は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];
}
はどんな提案を与え、ソリューション
メソッドに渡すhexColor文字列が6文字以上であることは確かですか? – jonkroll
文字列はどのように見えますか?あなたはそれをログに記録しようとしましたか、それともデバッガを調べてみましたか? –