iPhoneアプリのUITextViewでいくつかの単語に色を付けようとしていますが、エラーが発生し、おそらくそれは不可能だと思い始めています...私はこのコードを使用しています:
-(void)colorText
{
NSString *word = @"duck";
NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] initWithString: explainationTV.text];
NSUInteger count = 0;
NSUInteger length = [attrString length];
NSRange range = NSMakeRange(0, length);
while(range.location != NSNotFound)
{
range = [[attrString string] rangeOfString:word options:0 range:range];
if(range.location != NSNotFound) {
[attrString addAttribute:NSBackgroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(range.location, [word length])];
[attrString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(range.location, [word length])];
range = NSMakeRange(range.location + range.length, length - (range.location + range.length));
count++;
}
}
[[self.explainationTV textStorage] setAttributedString:attrString];
}
そして、私はこのエラーが発生しています:
-[ UITextView textStorage]: インスタンス 0x1f26ca00 2013-10-16 20:59:41.711 に送信された認識されないセレクターインスタンス 0x1f26ca00' に送信されたセレクター
私は Mac アプリで同じコードを使用していますが、問題なく動作します...誰かが私が何か間違ったことをしているのか、それとも iPhone アプリで単に動作しないのかを知っていますか? 助けてくれてありがとう...マッシー