2014-09-25 51 views
0

我有這個tableViewController有單元格,我有一個標籤和一個imageView,我需要傳遞給下一個viewController。將值傳遞給下一個viewController不工作

在兩個代表在第一VC和第二VC的tableViewCells這些元素的聲明等

@property (weak, nonatomic) IBOutlet UIImageView *thumbnail; 
@property (weak, nonatomic) IBOutlet UILabel *fileName; 

一旦一個電池的公開內容按鈕被點擊的類,它觸發prepareForSegue:sender:,我有這樣

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 

    // the user tapped on the disclosure button of a tableView cell... get the cell 
    FileManagerTableViewCell *cell = (FileManagerTableViewCell *)sender; 

    // this is the next viewController that will show the cell in detail 
    FileManagerDetailVC *detail = [segue destinationViewController]; 

    detail.thumbnail.image = cell.thumbnail.image; 
    detail.fileName.text = cell.fileName.text; 

    // at this point, `cell.thumbnail.image` and `cell.filename.text` **are not nil** 
    // if I check `detail.thumbnail.image` and `detail.filename.text` when the detail 
    // is presented, they are nil 

} 

我試圖創建新的對象,希望這個問題是單元對象被釋放,所以我這樣做:

detail.thumbnail.image = [UIImage imageWithCGImage:[cell.thumbnail.image CGImage]]; 
    detail.fileName.text = [NSString stringWithString:cell.fileName.text]; 

或者乾脆

detail.thumbnail.image = [cell.thumbnail.image copy]; 
    detail.fileName.text = [cell.fileName.text copy]; 

沒有變化。

我在想什麼?

回答

1

在prepareForSegue被調用時,目標視圖控制器中的視圖尚未加載。奧特萊斯是零。

的數據,而不是用戶界面組件創建的屬性,如:

@property (strong, nonatomic) NSString *filenameText; 
@property (string, nonatomic) UIImage *thumbnailImage; 

//in prepareForSegue 
detail.thumbnailImage = cell.thumbnail.image; 
detail.filenameText = cell.fileName.text; 

// and in viewDidLoad of FileManagerDetailVC 
self.thumbnail.image = self.thumbnailImage; 
self.fileName.text = self.filenameText 

這將做的工作。

0

這裏不創建縮略圖,fileName對象是您分配值的主要問題。只需創建屬性WIRH UIImage,NSString類型,然後將這些值分配給thumbnail.image和完整的Name.text然後它將工作。

+0

你的意思是這樣做? 'detail.thumbnail.image = [UIImage imageWithCGImage:[cell.thumbnail.image CGImage]];'?不工作。對象是零。我已經爲我的問題添加了更多信息。 – SpaceDog 2014-09-25 18:42:09

相關問題