Objective c UITextView停留在零

Objective c UITextView停留在零,objective-c,xcode,Objective C,Xcode,我正在尝试设置UITextView,以便它在特定屏幕上显示消息。以下是相关代码: //In the header file IBOutlet UITextView* playerText; -(void)playerThatWon:(int)player; @property(nonatomic, retain) IBOutlet UITextView* playerText; //In the main file @synthesize playerText; - (void)p

我正在尝试设置UITextView,以便它在特定屏幕上显示消息。以下是相关代码:

//In the header file

IBOutlet UITextView* playerText;

-(void)playerThatWon:(int)player;

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


//In the main file

@synthesize playerText;

- (void)playerThatWon:(int)player
{
    if (player == 0) {[playerText setText:@""];}
    else if (player == 1) {[playerText setText:@"You win, Player 1!"];}
    else {[playerText setText:@"You win, Player 2!"];}
    BOOL text = [playerText hasText];
}

初始化该类后,将从其他类调用playerThatWon。“text”布尔值是我设置的,用于查看UITextView是否有任何文本,当我在调试器中检查它时,它返回NO。另外,当我在调试器中查看playerText时,它没有值或任何东西,就像它甚至没有初始化一样。IB中没有问题,我正确连接了它,那么我在这里做错了什么?

问题是连接没有加载,即NIB还没有加载。您可能应该声明一个可以设置的属性,稍后在
viewDidLoad
中将该属性设置为文本字段

根据日志输出,您的插座似乎连接不正确。至少,
playerText
未正确连接,因为它是
nil
。您必须重新检查该连接。

如何实例化此视图控制器并调用该方法?
EndView=[[EndScreenViewController alloc]initWithNibName:nil bundle:nil]
[EndView playerThatWon:1]
[自我呈现ModalViewController:EndView动画:是]Oh,并且在头文件add
NSLog(@“%@”,playerText)中正确初始化了EndViewplayerThatWon:
方法中选择code>,并告诉我们您得到了什么。
[会话开始于2011-06-16 18:59:01-0700.]2011-06-16 18:59:16.331 FunctionMachine[2148:207](null)
检查了它。它肯定连接到我在IB中设置的UITextView。它也在类中合成,我需要在文章中添加它…好的。添加
NSLog(“%@”,self)
playerThatWon:
方法并添加
NSLog(@“%@”,EndView)初始化它们的位置,并验证它们是否相同。更新了我的答案。NIB未加载,因此
playerText
nil
。你将不得不使用一个属性或实例变量作为中间人。它成功了!只需将其放入
viewDidLoad
方法。谢谢你的帮助!