0

I have a UITableView which contains a UIImage and a title per cell. I'm getting the image from my db which contains the path of the picture generate via the ALAssetsLibrary. Problem is whenever I include the photo in the table, I can't select the cell. Any help would be appreciated

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIndentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIndentifier];

if (!cell) {
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIndentifier];

}
Person *aPerson = [arrayOfPerson objectAtIndex:indexPath.row];

UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];

UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
cellBackgroundView.image = background;
cell.backgroundView = cellBackgroundView;

UILabel *myLabel = (UILabel *) [cell viewWithTag:101];
myLabel.text = aPerson.title;

NSString *stPath = [NSString stringWithFormat:@"%@", aPerson.photo];
NSURL *urlNow = [NSURL URLWithString:stPath];

ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:urlNow resultBlock:^(ALAsset *imageAsset) {
    ALAssetRepresentation *r = [imageAsset defaultRepresentation];
    UIImageView *myImageView = (UIImageView *)[cell viewWithTag:100];
    myImageView.image = [UIImage imageWithCGImage: r.fullResolutionImage];
    //[cell.contentView addSubview:myImageView];
    [self.tableView reloadData];
} failureBlock:nil];
return cell;
n00bProgrammer
  • 4,261
  • 3
  • 32
  • 60
Ced
  • 3
  • 1
  • What exactly do you mean by "can't select the cell"? Did you implement didSelectRowAtIndexPath? – Mike Jan 19 '14 at 04:00

1 Answers1

1

New image view objects are configured to disregard user events by default. If you want to handle events in a custom subclass of UIImageView, you must explicitly change the value of the userInteractionEnabled property to YES after initializing the object.

UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
cellBackgroundView.userInteractionEnabled = YES;

Note:

When you are dealing with Asset Library images, Please look at my this answer that may help you for better performance.

Community
  • 1
  • 1
Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102
  • Thanks for the reply. I tried adding enabling user interaction both via IB and program but it's still not working – Ced Jan 19 '14 at 00:31