Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 977
mr-sk Avatar asked Dec 05 '25 10:12

mr-sk


2 Answers

Double check if the outlets are done in IB. That's probably the reason (textView is probably nil here).

like image 141
gcamp Avatar answered Dec 07 '25 09:12

gcamp


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

like image 45
bobDevil Avatar answered Dec 07 '25 11:12

bobDevil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!