2011-06-17 24 views
2

我想設置一個UITextView,以便它在某個屏幕上顯示一條消息。下面是相關的代碼: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時,它沒有任何值或任何東西,比如它甚至沒有初始化。國際文憑組織沒有任何問題,我把它正確地連接起來了,所以我在這裏做錯了什麼?

+0

你如何實例化這個視圖控制器和調用方法? – 2011-06-17 00:52:38

+0

'EndView = [[EndScreenViewController alloc] initWithNibName:nil bundle:nil];' '[EndView playerThatWon:1];' '[self presentModalViewController:EndView animated:YES];' – RaysonK 2011-06-17 01:10:05

+0

噢,EndView已經正確初始化頭文件 – RaysonK 2011-06-17 01:12:00

回答

1

問題是連接未加載,即NIB尚未加載。您應該聲明一個可以設置的屬性,並在稍後viewDidLoad中將該屬性設置爲文本字段。

根據日誌輸出,它看起來像你的網點沒有正確連接。至少, playerText未正確連接,因爲它是 nil。您將不得不重新檢查該連接。

+0

檢查它。它絕對連接到我在IB中設置的UITextView。這也是在課堂上綜合的,我需要在帖子中加入... – RaysonK 2011-06-17 02:12:16

+0

好的。向'playerThatWon:'方法添加'NSLog(「%@」,self);'添加'NSLog(@「%@」,EndView);'在哪裏初始化它們並驗證它們是否相同。 – 2011-06-17 02:21:40

+0

是的,他們匹配 – RaysonK 2011-06-17 02:38:49