2014-09-25 52 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

相关问题