Reputation: 21237
I have a UITextView
that upon initialization displays a string from a database and formats it using an NSAttributedString
. This works fine. If the user clicks a 'New Entry' button, I need to clear the text view and allow the user to enter their own text. I do not want the attributes from the attributed string to follow along. (I just want an unformatted string). However, as soon as the user starts typing, their text is formatted like it was when it was displaying server data. I don't know how to reset this.
I've tried:
self.notes = @"";
self.notes = nil;
I thought that setting the field to nil
would solve it for sure, but it doesn't. Can anyone tell me how to do this? Thank you.
Upvotes: 0
Views: 1454
Reputation: 90551
Set the text view's typingAttributes
property to an empty dictionary (or maybe nil
).
Upvotes: 2
Reputation: 1611
Try this to clear the Attributed feature
NSMutableAttributedString *originalMutableAttributedString = //users' string…
NSRange originalRange = NSMakeRange(0, originalMutableAttributedString.length);
[originalMutableAttributedString setAttributes:@{} range:originalRange];
textView.text = originalMutableAttributedString;
Upvotes: 1