我是oop和objective-c的新手。我有一個從我的手機加載照片的collectionView。我想原因請看另一個視圖控制器,使我的資產顯示@全resolution.I遵循這個帖子:set UIImageView.image in prepareForSegue羅布Mayoff以及與此上來了,這是我的主要VC代碼:分段並在另一個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。我當然做錯了事,真的需要你的幫助。我只是不知道該做什麼了再次感謝。
我現在明白了。你和菲利普米爾斯是我的生活救星:)如果我有任何其他問題,我會讓你知道! – QuiBongJin