Pergunta

Here's my prepareForSegue:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqual:@"cameraToRollsSegue"]){
    ALRollsTableViewController *rollsTableViewController = (ALRollsTableViewController *)[segue destinationViewController];
    Camera *c = [self.fetchedResultsController objectAtIndexPath:[self.tableView indexPathForSelectedRow]];
    NSLog(@"CAMERA FROM INSIDE PREPARE FOR SEQUE: %@", c);
    rollsTableViewController.selectedCamera = c;
}

}

I verify that the camera is not null with NSLog:

CAMERA FROM INSIDE PREPARE FOR SEQUE: <Camera: 0x8dc1400> (entity: Camera; id: 0x8dafba0 <x-coredata://A415F856-5F21-4F08-9CAB-4B2A023B55C3/Camera/p1> ;

ALRollsTableViewController viewDidLoad:

- (void)viewDidLoad
{
    NSLog (@"ROLLS TABLE VIEW CONTROLLER : viewDidLoad!");
    NSLog(@"(selected camera = %@", self.selectedCamera);
 }

results in:

ROLLS TABLE VIEW CONTROLLER : viewDidLoad!
(selected camera = (null)

What might I be doing wrong here that the property is not being set?


UPDATE

With matt's help I've determined that the instance of my destination view controller in my prepareForSeque does not match the actual destination view controller:

rollsTableViewController FROM SEGUE: <ALRollViewController: 0x8d90bf0> 
rollsTableViewController FROM viewDidLoad in rollsTableViewController: <ALRollsTableViewController: 0x8c5ab00> 

I don't know why this is the case or what to do to fix it.

Foi útil?

Solução

Post-chat summary:

Well, it was complicated! But basically you were saying this:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqual:@"cameraToRollsSegue"]){
    ALRollsTableViewController *rollsTableViewController = (ALRollsTableViewController *)[segue destinationViewController];
    // ...
}

The problem was that [segue destinationViewController] was not an ALRollsTableViewController. Thus you were not talking to the instance you thought you were talking to, and you were not talking to an instance of the class you thought you were talking to.

The amazing thing is that your code didn't crash when it ran. You were saying this:

rollsTableViewController.selectedCamera = c;

But rollsTableViewController was not in fact an ALRollsTableViewController. You lied to the compiler when you cast incorrectly. Yet you didn't crash when that line ran. Why not? It's because you've got lots of classes with @property selectedCamera! So you were setting the property of a different class. But a property with that same name did exist in that class, so you didn't crash. Thus you didn't discover that this was the wrong class and the wrong instance.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top