1

我的视图控制器包含一个 UIImageView 和一个 UITextView 下面。这是我的代码:

#import <UIKit/UIKit.h>

@interface DescriptionViewController : UIViewController

@property (nonatomic, strong) IBOutlet UIImageView *descriptionImage;
@property (nonatomic, strong) IBOutlet UITextView *descriptionText;

@property (nonatomic, strong) NSString *text;
@property (nonatomic, strong) NSString *image;

@end


@interface DescriptionViewController ()

@end

@implementation DescriptionViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.descriptionText = [[UITextView alloc] init];

    self.descriptionImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.image]]];
    self.descriptionText.text = self.text;
    NSLog(@"%@", self.descriptionText.text);
}

@end

我的代码没有显示在 textview 中,但我可以使用 NSLog 打印它。
可能是什么问题呢 ?

4

1 回答 1

4

你在这里初始化一个新的UITextView。-

self.descriptionText = [[UITextView alloc] init];

这样,您将获得一个UITextView未与主视图链接的新视图。删除该行并确保descriptionText在您的xibstoryboard.

但是,如果您的意图实际上是以编程方式UITextView从头开始创建一个新的,那么您还必须以编程方式将其添加到您的主视图中。

于 2013-10-05T10:37:20.127 回答