Objective-C / Xcode无法在UITextView中添加/更改文本

时间:2012-08-04 07:18:19

标签: objective-c uitextview

出于某种原因,我无法从代码中更改或添加UITextView中的文本。

我已经制作了Outlet并且已连接(全部在IB中) - 没有任何反应。 甚至尝试添加-setNeedsDisplay 我需要设置一些属性吗? - 这让我疯了......

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITextViewDelegate> {
    UITextView *textInfoView;
}

@property (nonatomic, retain) IBOutlet UITextView *textInfoView;


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    textInfoView.text = @"Test";
}

-(void)viewDidAppear:(BOOL)animated{
    textInfoView.text = @"Test";    
    textInfoView.text = [textInfoView.text stringByAppendingString:@"Line2"];
    [textInfoView setNeedsDisplay];

2 个答案:

答案 0 :(得分:1)

看起来,这个代码不会更新UITextView中的文本真的很奇怪。我试过了它对我有用......我认为你没有在界面构建器中正确链接Outlet,或者你没有将视图控制器关联到你的视图......

答案 1 :(得分:0)

UPS - 明白了......

忘了@synthesize ......

由于某种原因,我没有在Xcode 4.4中收到警告或“设置错误”,也许这是一个版本错误?