Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attributed text in UITextView causing a crash

This is my code to display an attributed string in a UITextView

NSMutableAttributedString *recipeString =[[NSMutableAttributedString alloc]init];
    [recipeString appendAttributedString:string1];
    [recipeString appendAttributedString:string2];
    [array addObject:recipeString];

This code is inside a for loop. string1 and string2 are NSMutableAttributedStrings.

After that:

self.textView.text = [array objectAtIndex:self.appDelegate.selectedCell];

The text view is an IBOutlet.

It crashes with this exception:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteAttributedString _isCString]: unrecognized selector sent to instance 0x8e866f0'

Any ideas on how to fix this crash?

like image 772
Moon Cat Avatar asked Feb 13 '23 04:02

Moon Cat


1 Answers

I had to use the attributedText property of UITextView:

self.textView.attributedText = [array objectAtIndex:self.appDelegate.selectedCell];
like image 181
Moon Cat Avatar answered Feb 16 '23 03:02

Moon Cat