gpt4 book ai didi

ios - 无法使用 initWithCoder 影响 UITextView 内容

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:15:11 26 4
gpt4 key购买 nike

我正在尝试在应用程序启动时在我的 UITextView 中显示一个字符串。我的界面中有一个 UIView 和一个 UITextView,还有一个 socket myText,它连接到 UITextView。它似乎没有用,我也说不出为什么....

这里是有问题的代码:

主视图.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface MainView : UIView {

IBOutlet UITextView *myText;

}
@end

主视图.m

@implementation MainView

-(id) initWithCoder:(NSCoder *)coder {


if ((self = [super initWithCoder:coder]) != nil)
{
NSLog(@"initWithCoder executed");
myText.text = @"Hello, World!";
}

return self;
}

@end

打印了 NSLog() 消息,所以我假设 myText.text 确实设置为 @"Hello World",但这没有反射(reflect)在我的 UITextView 中。这里挂断在哪里?如果有帮助,这是我实际应用程序的简化版本,当我将相同的 myText.text = @"Hello, World!"; 放入响应按钮按下的方法时,更改反射(reflect)在 TextView 中。

最佳答案

Nib 连接不一定存在于 initWithCoder: 中——仅仅因为该对象已解冻并不意味着 nib 中的其他所有内容都已解冻。你想要 awakeFromNib

关于ios - 无法使用 initWithCoder 影响 UITextView 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2264357/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com