Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current attributed string in non-editable UITextView?

I'm setting the appearance of a UITextView's text in the storyboard via the attributed string properties. However when I try to access it at runtime in order to copy the attributes object, it returns null.

NSAttributedString *atrString = self.contentTextView.attributedText;
NSLog(@"atrString = %@", atrString);

Outputs

2013-09-20 14:44:19.572 PageTest[69125:70b] atrString = (null)

I haven't worked with attributed strings before so I'm sure I'm doing something wrong, but scouring the documentation has still left me empty handed. Any assistance would be appreciated. Thanks!

like image 437
Murdock Avatar asked Sep 20 '13 21:09

Murdock


1 Answers

Just had the same issue: can't access attributedText on TextView if it is not marked as selectable in Interface Builder (Xcode 6.1). No problem though if the same is done in code. In my case I subclass UITextview:

-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self)
    {
        self.selectable = NO;
    }
    return self;
}

So I assume something is not quite perfect with IB. Again)

like image 153
user2260054 Avatar answered Oct 02 '22 14:10

user2260054