prepareForSegue destination controller property not being set

柔情痞子 提交于 2019-12-02 01:29:06

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!