0

I may have found a bug in iOS and I'm not sure how to overcome it. I am losing my textView style as soon as the database populates it with content.

That is what happens:

In my storyboard I have the following textView

enter image description here

As soon as I populate the textView manually or from my object as per below it loses its style.

  if let object  = currentObject.objectForKey("postText") as? String {
            postTextView.text = "the text field has some text added"
        }

On simulator, showing the style is lost.

enter image description here

Also, other situation:

I may lose the style as well if I uncheck the editable box as per the image bellow.

enter image description here

GuiSoySauce
  • 1,763
  • 3
  • 24
  • 37

3 Answers3

1

Here's an older answer which hopefully answers your question and solves your problem. Is seems indeed to be a bug. https://stackoverflow.com/a/19115950/543224

Community
  • 1
  • 1
rodskagg
  • 3,827
  • 4
  • 27
  • 46
  • The bug seems to be that the styling is removed if selectable is set to FALSE, at least according to the link I posted. But to clarify, you have it set to TRUE and get this bug anyway? – rodskagg Dec 06 '15 at 23:29
  • My one was selectable. I did test it in both ways and worked fine. Problem was when making it not editable. I have to make it editable on storyboard and non editable on viewDidLoad. – GuiSoySauce Dec 07 '15 at 01:38
1

Did you set the attributes on the text view itself (i.e. the text view text is "plain", and not "attributed")? Or did you use attributed text?

If the latter, it's quite normal that if you replace the attributed text with plain text with no attributes, it reverts to the attributes of the text view itself.

Make sure the type is set to "plain", and that you set the attributes on the text view itself, not on the text inside it. Or use the attributedText and not the text property of your text view, with appropriate attributes.

jcaron
  • 17,302
  • 6
  • 32
  • 46
  • It was set to plain. On attributed with style to field and not pieces of text didn't work as well. The only way I got it to work was by making it editable on the storyboard and then making it `.editable = false` programmatically. – GuiSoySauce Dec 07 '15 at 01:36
0

I guess that you update UI on from background. If you want update UI you have to update in main queue. If you don't do it, some strange issue will come. So you can change your code to:

dispatch_async(dispatch_get_main_queue()) { () -> Void in
    if let object  = currentObject.objectForKey("postText") as? String {
        postTextView.text = "the text field has some text added"
    }

}
vien vu
  • 4,277
  • 2
  • 17
  • 30