I’m trying to set up a UITextView so that it displays a message on a certain screen. Here’s the relevant code:
//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 gets called from a different class after this class gets initialized. The “text” boolean was something that I set up to see if the UITextView had any text, and it returns NO when I check it in the debugger. Also, when I look at playerText in the debugger, it has no values or anything, like it wasn’t even initialized. There are no problems in the IB, I hooked it up right, so what am I doing wrong here?
The problem is that the connections are not loaded i.e. the NIB is not loaded yet. You should probably declare a property that you can set and later in
viewDidLoadset the property to the text field.Based on the log output, it looks like your outlets aren’t connected properly. At least,
playerTextisn’t connected properly as it isnil. You will have to recheck that connection.