How to get current attributed string in non

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!


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)


It should works. May be you forgot to connect IBOutlet contentTextView to the storyboard?

Try to print contentTextView object:

NSLog(@"contentTextView = %@", self.contentTextView);
链接地址: http://www.djcxy.com/p/15998.html

上一篇: 理解node.js中递归函数的承诺

下一篇: 如何获得非当前的属性字符串