prepareForSegue目标控制器属性未设置 [英] prepareForSegue destination controller property not being set

查看:125
本文介绍了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;
}

}

我使用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);
 }

结果:

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

在这里我可能做错了该房产没有设置?

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

更新

在matt的帮助下,我确定我的prepareForSeque中的目标视图控制器的实例与实际的目标视图控制器不匹配:

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.

推荐答案

聊天后摘要:

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];
    // ...
}

问题在于 [segue destinationViewController] 不是 ALRollsTableViewController。因此,你没有和你认为你正在谈论的实例交谈,而且你没有和你认为你正在谈论的课程实例交谈。

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;

但是 rollsTableViewController 实际上并不是ALRollsTableViewController 。当你错误地投射时,你骗了编译器。但是当那条线路运行时你并没有崩溃。为什么不?这是因为你有很多类 @property selectedCamera !所以你设置了不同类的属性。但是在该类中存在具有相同名称​​的属性,因此您没有崩溃。因此,您没有发现这是错误的类和错误的实例。

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.

这篇关于prepareForSegue目标控制器属性未设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆