Unable to set text in NSTextView
::Edit:: It works now? haha, maybe I just didn't save my latest IB...who the hell knows. Thanks!
Hey,
This is my first time playing around with desktop applications (I have experience with iphone applications) and开发者_运维知识库 I'm stuck - My text view will not update to show any text:
.m:
@synthesize textView;
NSString *txt = [[[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding] autorelease];
NSLog(@"txt = %@", txt);
[textView setString:txt];
.h:
IBOutlet NSTextView *textView;
}
@property(nonatomic, retain) IBOutlet NSTextView *textView;
And IB says textView -> Text View, so everything looks good:
- NSLog above outputs the contents of the url resource Im fetching
So, what am I missing?
Double check if the outlets are done in IB. That's probably the reason (textView is probably nil
here).
Where is this setString
code being called? It's possible the IB outlet isn't instantiated yet. You can check this with a simple
if (textView) {
NSLog(@"textView is not nil);
} else {
NSLog(@"textView is nil");
}
To be sure that everything is set up when you call this, make sure it's after 'awakeFromNib' is called in any objects created through IB.
See NSNibAwaking Protocal
Can you double check NSTextView properties like isEditable, textColor etc to make sure none of them are set incorrectly.
Other than that the code looks good.
I reconnected everything in IB, saved, rebuilt and it worked...= [
精彩评论