Bound text in UITextView causing crash

This is my code for displaying an attribute string in a UITextView

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

This code is inside the loop for. string1and string2are NSMutableAttributedStrings.

Thereafter:

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

The textual representation is 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 error?

+4
source share
2 answers

I had to use the property attributedText UITextView:

self.textView.attributedText = [array objectAtIndex:self.appDelegate.selectedCell];
+8
source

For future users:

-[NSConcreteAttributedString mutableString]: unrecognized selector sent to instance

it can also be caused by the fact that in the above example string1or string2isnil

0
source

Source: https://habr.com/ru/post/1537268/


All Articles