我是oop和objective-c的新手。我有一个 collectionView 从我的手机加载照片。我想继续使用另一个 ViewController,以便我的资产以@全分辨率显示。我关注了这篇文章: Rob Mayoff在 prepareForSegue 中设置 UIImageView.image并想出了这个,这是我的主要 VC 代码:
- (void)viewDidLoad
{
[super viewDidLoad];
void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop)
{
if (result != NULL)
{
NSLog(@"See Asset: %@", result);
[_gallery addObject:result];
}
};
void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
if(group != nil)
{
[group enumerateAssetsUsingBlock: assetEnumerator];
}
[self.collectionView reloadData];
};
_gallery = [[NSMutableArray alloc]init];
_library = [[ALAssetsLibrary alloc] init];
[_library enumerateGroupsWithTypes: ALAssetsGroupAlbum
usingBlock: assetGroupEnumerator
failureBlock: ^(NSError *error)
{
NSLog(@"Failure");
}];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return _gallery.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
ViewControllerCell *myCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];
_asset = [_gallery objectAtIndex:indexPath.row];
_photo =[UIImage imageWithCGImage:[_asset thumbnail]] ;
myCell.myImage.image = _photo;
return myCell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
_asset = [_gallery objectAtIndex:indexPath.row];
_photo = [UIImage imageWithCGImage:[_asset thumbnail]];
ALAssetRepresentation *rep = [_asset defaultRepresentation];
CGImageRef ref = [rep fullResolutionImage];
_img = [UIImage imageWithCGImage: ref];
}
//the segue is set to modal
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"ShowPhoto"]) {
PhotoZoomController *photoZoom = segue.destinationViewController;
photoZoom.object = sender;
}
}
现在为了显示我的完整图像,我在目标 VC 的 viewDidLoad 方法中执行此操作:
- (void)viewDidLoad
{
ViewController *vc = [[ViewController alloc] init];
_image = vc.img;
[super viewDidLoad];
_largePhoto.image = _image; / *largePhoto is the UIImageView @property declared
in destination VC.h */
}
我得到一个空白的 imageView。我当然做错了什么,真的需要你的帮助。我只是不知道该怎么办了提前谢谢。