1

私のviewDidLoadでは、UILabelsとUITextFieldsを取得してテキストを表示できますが、UITextViewは表示できません。以下のコードで何か間違ったことをしていますか?

- (void)viewDidLoad {

[super viewDidLoad];

UIView* headerWrapper = [[UIView alloc] init];

//tap gesture is for each section so we can click on it
UITapGestureRecognizer *headerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showContent:)];

header = [[UIView alloc] initWithFrame: CGRectMake(10.0, 10.0, 738.0, 40.0)];
header.backgroundColor = [UIColor blackColor];

//get the header frame
CGRect headerFrame = header.frame;

//add the gesture
[headerWrapper addGestureRecognizer:headerTap];

//add a label
UILabel* lblSectionTitle = [[UILabel alloc] initWithFrame: CGRectMake(10.0, 3.0, headerFrame.size.width, 24.0)];
lblSectionTitle.text = @"This is a test";
lblSectionTitle.font = [UIFont fontWithName:@"Helvetica" size:20.0];
lblSectionTitle.textColor = [UIColor whiteColor];
lblSectionTitle.backgroundColor = [UIColor clearColor];
[header addSubview:lblSectionTitle];

[headerWrapper addSubview:header];

//this is the wrapper for the content
UIView* contentView = [[UIView alloc] initWithFrame:CGRectMake(10.0, headerFrame.size.height + 15.0, headerFrame.size.width, 200.0)];
contentView.backgroundColor = [UIColor redColor];

UITextView* tvContent = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, headerFrame.size.width, 200.0)];
[tvContent setText:@"This is a content test."];
tvContent.textColor = [UIColor blackColor];
tvContent.backgroundColor = [UIColor clearColor];
tvContent.font = [UIFont fontWithName:@"Trebuchet" size:18.0];

[contentView addSubview:tvContent];
[headerWrapper addSubview:contentView];
[self.view addSubview:headerWrapper];

NSLog(@"%@", tvContent.text);

}
4

1 に答える 1

1

私は今日この問題を抱えていて、変更することで解決しました:

[tvContent setText:@"This is a content test."];

tvContent.text = @"This is a content test.";

最初は、問題は UITextView が読み込まれていないことにあると思いました。しかし、インターフェイス ビルダーで読み込まれて接続されていることを確認した後 (プログラムで実行しているため、あなたのケースではありません)、setText を呼び出す代わりに、直接属性を使用してコンテンツを設定することしかできませんでした。

それが役に立てば幸い!

于 2012-10-08T15:47:02.070 に答える