0

I'm having trouble trying to figure out how one would pass information in a UITableViewCell to the view that appears after the button "your play" is pushed. Each cell has the property string gameId associated with it which is unique to each cell and is the information I would like to pass:

The following code shows the creation of the cells. The NSLog statement outputs the correct gameId during testing:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"gameCell";
GameCell *cell = (GameCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

PFObject *myPartners = [self.games objectAtIndex:indexPath.row];
cell.partnerName.text = [myPartners objectForKey:@"receiverName"];
cell.gameId = myPartners.objectId;
NSLog(@"Cell game: %@",cell.gameId);
return cell;
}

In the GameCell class, the following method is used to change the view and pass the gameId: It sets CameraViewControllers property "gameObjectId" equal to "gameId"

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"showCamera"]){
    CameraViewController *cameraView = (CameraViewController *)segue.destinationViewController;
    cameraView.gameObjectId = self.gameId;
    [segue.destinationViewController setHidesBottomBarWhenPushed:YES];
}
}

However when the view loads, the gameObjectId value is null.

Can someone please help me with this?


gameObjectId is in the CameraViewController class as:

@property (strong,nonatomic) NSString *gameObjectId;

gameId is in the GameCell class as:

@property (strong,nonatomic) NSString *gameId;

enter image description here

enter image description here

SMD01
  • 101
  • 1
  • 13

1 Answers1

2

You can't put prepareForSegue in your cell class; it's a UIViewController method, so it's not going to get called if you have it in your cell class. You need to move that to your view controller, and use the sender argument (which will be the cell you touched) to get the indexPath. With the indexPath, you can query your array to get the value to pass -- you shouldn't take the value from the cell, you should get the value from your model.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • I've added a picture of a cell. When the button "your play" is pushed, how would I retrieve which cell it was called from? – SMD01 Jul 12 '14 at 22:05
  • @ShawnNewDev, there are several ways. One way is to give your button a tag that's equal to the indexPath.row. – rdelmar Jul 12 '14 at 23:49