2013-03-12 87 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