简体   繁体   English

无法在NSTextView中设置文本

[英]Unable to set text in NSTextView

::Edit:: It works now? ::编辑::现在可以用了吗? haha, maybe I just didn't save my latest IB...who the hell knows. 哈哈,也许我只是没有保存我最新的IB ...谁知道呢。 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: 这是我第一次玩桌面应用程序(我有使用iphone应用程序的经验),但遇到了麻烦-我的文本视图不会更新以显示任何文本:

.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: IB说textView-> Text View,所以一切看起来都不错:

  • NSLog above outputs the contents of the url resource Im fetching 上面的NSLog输出url资源的内容

So, what am I missing? 那么,我想念什么?

Double check if the outlets are done in IB. 仔细检查出口是否在IB中完成。 That's probably the reason (textView is probably nil here). 这可能是原因(此处的textView可能为nil )。

Where is this setString code being called? setString代码在哪里被调用? It's possible the IB outlet isn't instantiated yet. IB插座可能尚未实例化。 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. 为确保在调用时一切都已设置,请确保在通过IB创建的任何对象中调用“ awakeFromNib”之后。

See NSNibAwaking Protocal 请参阅《 NSNIb唤醒协议》

Can you double check NSTextView properties like isEditable, textColor etc to make sure none of them are set incorrectly. 您是否可以再次检查NSTextView属性(例如isEditable,textColor等),以确保没有错误地设置它们。

Other than that the code looks good. 除此之外,代码看起来还不错。

我重新连接了IB中的所有内容,进行了保存,重建,并且可以正常工作... = [

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM