我需要一些帮助来确定如何将数据从我的集合视图传递到详细视图控制器。我首先简单地传递图像。我的代码如下:
的ViewController:
-(MyCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
PFObject *imageObject = [imageFilesArray objectAtIndex:indexPath.row];
__block UIImage *MyPicture = [[UIImage alloc]init];
PFFile *imageFile = [imageObject objectForKey:@"test"];
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
MyPicture = [UIImage imageWithData:data];
cell.CollectionImg.image = [UIImage imageWithData:data];
cell.cellLabel.text = [object objectForKey:@"phone"];
}
}];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
TopDetailViewController *detailVC = [[TopDetailViewController alloc] initWithNibName:@"TopDetailViewController" bundle:[NSBundle mainBundle]];
detailVC.img= [imageFilesArray objectAtIndex: indexPath.row];
[self.navigationController pushViewController:detailVC animated:YES];
}
详情视图:
·H
@property (nonatomic, strong) IBOutlet UIImageView *imageView;
@property (nonatomic, strong) IBOutlet NSString *img;
的.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageView.image = [UIImage imageNamed:self.img];
// Do any additional setup after loading the view from its nib.
}
如果有人可以帮助我,我会非常感激。
答案 0 :(得分:0)
您只能使用[UIImage imageNamed:]来检索应用包中的图片。看起来您在运行时基于PDF文件创建这些图像,因此只需将字符串传递给详细视图并使用[UIImage imageNamed:]加载它就不会起作用。您应该将引用传递给图像或PFFile对象,以便详细视图可以自己生成图像。