简体   繁体   English

未设置prepareForSegue目标控制器属性

[英]prepareForSegue destination controller property not being set

Here's my prepareForSegue: 这是我的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: 我使用NSLog验证相机不为空:

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

ALRollsTableViewController viewDidLoad: 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 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: 借助matt的帮助,我确定我的prepareForSeque中目标视图控制器的实例与实际的目标视图控制器不匹配:

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. 我不知道为什么会这样或如何解决。

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. 问题是[segue destinationViewController] 不是 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. 但是rollsTableViewController实际上不是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 ! 这是因为您有很多使用@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. 因此,您不会发现这是错误的类和错误的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM