2013-03-12 62 views
0

我想将图像发送到下一个scent.but失败。prepareForSegue中的赋值为false

这里是我的代码

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    NSLog(@"prepareForSegue start"); 
    NSLog(@"count is %d",count); 

    //bigStyle1 is a NSArray,full of UIImage 
    //bigImage is a UIImageView outlet 
    if ([bigStyle1 objectAtIndex:count]==nil) { 
     NSLog(@"no array image"); 
    } 
    viewController3.bigImage.image=[bigStyle1 objectAtIndex:count]; 
    if (viewController3.bigImage.image==nil) { 
     NSLog(@"no controller image"); 
    } 

    NSLog(@"secondToThird");   
    NSLog(@"prepareForSegue end"); 
} 

这里是Xcode的日志

2013-03-12 15:15:38.683 animation[1876:f803] prepareForSegue start 
2013-03-12 15:15:50.825 animation[1876:f803] count is 0 
2013-03-12 15:17:10.829 animation[1876:f803] no controller image 

看来这个问题是image.Why分配的任务失败了吗?

UPDATE viewController3不nil.But bigImage是nil.I不知道why.I实际上bigImage连接到图像视图

+0

你确定'bigStyle1'不为空? – Fonix 2013-03-12 07:54:03

+2

'viewController3'是segue的目的地吗?设置'viewController3'的代码在哪里? – 2013-03-12 07:57:04

+0

我敢肯定bigStyle1不是null,viewController3是由storyboard实例化的。 – 2013-03-12 08:04:58

回答

2

我怀疑你打算viewController3要的目的地Segue公司。在这种情况下,你应该设置这样的:

viewController3 = segue.destinationViewController; 

我还怀疑viewController3.bigImageUIImageView。如果是这样,您有问题,因为viewController3尚未在系统发送prepareForSegue:sender:时加载其视图层次结构,因此尚未设置viewController3.bigImage。它是零,并设置零的属性什么都不做(没有警告或错误信息)。

最好直接给viewController3image属性,并将该图像存储在该属性上。然后,在viewController3viewDidLoad方法中,将该属性的图像复制到self.bigImage.image

或者,您可以奶酪它迫使viewController3只是要求它为它的视图加载其prepareForSegue:sender:观点:

[viewController3 view]; // forces it to load its view hierarchy if necessary 
viewController3.bigImage.image = [bigStyle1 objectAtIndex:count]; 
+0

非常感谢。你的回答非常好。 – 2013-03-12 08:14:12