mercredi 31 décembre 2014

Data passed between ViewControllers and being Reset?

I'm simply trying to pass an NSInteger between 2 Viewcontrollers and for some reason, the data keeps getting reset. What I mean by reset is as I do the following:



- (void)pickerView:(AKPickerView *)pickerView didSelectItem:(NSInteger)item
{
PlayViewController *playScreen = [[PlayViewController alloc] init];
playScreen.playerNumber = item;
NSLog(@"%d", playScreen.playerNumber);
}


The NSLog would then print out whatever the index of the chosen object is but once I go to PlayViewController and do the following switch statement:



switch (self.playerNumber){
case 0:
theView.playerComment.text = @"You, again";
playerScores[0]++;
break;

case 1:
if (numberPressed % 2){
theView.playerComment.text = @"Player 2's Turn";
playerScores[0]++;
}
else {
theView.playerComment.text = @"Player 1's Turn";
playerScores[1]++;
}
break;
and so on.... the code would always receive 0 as the value of playerNumber...


Also, in PlayViewController.h, the variable player number is declared as such:



@property (nonatomic) NSInteger playerNumber;



Aucun commentaire:

Enregistrer un commentaire