Cannot set readyForSegue target controller property

Here is 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 in the 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); } 

leads to:

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

What can I do wrong here when the property is not set?


UPDATE

With matte help, I determined that the instance of my destination controller in my readyForSeque file does not match the actual view controller:

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

I do not know why this is so or what to do to fix it.

+2
source share
1 answer

Summary after chat:

Well, that was hard! But basically you said this:

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

The problem was that [segue destinationViewController] not ALRollsTableViewController. That way, you did not talk to the instance you were thinking about, who you were talking to, and you did not talk to the instance of the class you were talking about.

The amazing thing is that your code did not crash when it ran. You said this:

 rollsTableViewController.selectedCamera = c; 

But rollsTableViewController not really an ALRollsTableViewController. You lied to the compiler during an incorrect installation. But you did not work when this line ran. Why not? This is because you have many classes with @property selectedCamera ! Thus, you set the property of another class. But a property with the same name existed in this class, so you did not work. So you did not find that it was the wrong class and the wrong instance.

+1
source

Source: https://habr.com/ru/post/988662/


All Articles