Got an UIIMagePickerController in my "newPlayerVC" that saves an thumbnail image (after I resized it down to 100x100 px) to the AssetLibrary without any problems.
Dirrectly after saving the image I put in another call to the AssetLibrary again to fetch the just saved image to show the user (and also check that it works ok). That call looks like this;
// Display new thumbnail via AssetLIbrary call
__block UIImage *_image = nil;
[assetLib assetForURL:(playerImageURL)
resultBlock:^(ALAsset *asset) {
_image = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]];
NSLog(@"Got the asset thumbnail, %@",_image);
[playerImageButton setImage:_image forState:UIControlStateNormal];
}
failureBlock:^(NSError *error) {
NSLog(@"Asset (image) fetch failed because %@",error);
}];
So far it works just fine. The terminal confirm logs with: "p.playerImage = assets-library://asset/asset.JPG?id=A79242D5-BC91-490B-BC37-0A9F529675EE&ext=JPG" and "Got the asset thumbnail, UIImage: 0xcb5b8a0" - so I know it's getting the image from the asset library.
But then I try to do a very simular call from my "playerTableVC" to populate a tableview with that earlier saved image to an UIView in my custom cell - it just dont work (the custom cell is ok and wok with static images). Also I get no errors or warnings either from Xcode. That code looks like this from the function "- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath";
// Set up Asset library
ALAssetsLibrary *assetLib = [[ALAssetsLibrary alloc]init];
__block UIImage *_image = nil;
[assetLib assetForURL:[NSURL URLWithString:p.playerImage]
resultBlock:^(ALAsset *asset) {
_image = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];
NSLog(@"Got the asset thumbnail, %@", _image);
}
failureBlock:^(NSError *error) {
NSLog(@"Asset fetch failed: %@",error);
}];
// If no cell, create new
if (cell == nil) {
cell = [[CellPlayer alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
// If cell present, assign values
NSLog(@"p.playerImage = %@", p.playerImage); // Check = ok
// Check if imageurl is empty = default image else the user choosen image
if ([p.playerImage isEqualToString:@""]) {
cell.cellPlayerIcon.image = [UIImage imageNamed:@"defaultImageFrame_114x114"];
// Add sortingorder ("player position") to tableview
cell.cellPlayerStarIcon.text = [NSString stringWithFormat:@"%i", (indexPath.row +1)];
} else {
cell.cellPlayerIcon.image = _image; // = NO IMAGE IN CELL?
// Add sortingorder ("player position") to tableview
cell.cellPlayerStarIcon.text = [NSString stringWithFormat:@"%i.", (indexPath.row +1)];
}
cell.cellPlayerName.text = p.playerName;
cell.cellPlayerTime.text = p.playerTime;
cell.cellPlayerTimestamp.text = [NSString stringWithFormat:@"%@", p.playerTimeStamp]; // @"2012-10-01 @ 8:06";
return cell;
}
I belive I doing something wrong with the setting of the UIIMage in populating the cell above. Everything else works ok an also with a static UIImage. Tried a lot of variations of this and believe I know finally gone "code-flind"... ;-)
Got any solutions, tips, pointers etc? Thanks :-)