UITableView单元格不会选择

时间:2014-01-18 08:03:00

标签: uitableview alassetslibrary

我有一个UITableView,其中包含UIImage和每个单元格的标题。我从我的数据库中获取图像,其中包含通过ALAssetsLibrary生成的图片的路径。问题是每当我在表格中包含照片时,我都无法选择单元格。任何帮助将不胜感激

- (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;

1 个答案:

答案 0 :(得分:1)

默认情况下,新图像视图对象配置为忽略用户事件。如果要处理UIImageView的自定义子类中的事件,则必须在初始化对象后将userInteractionEnabled属性的值显式更改为YES

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

注意

当您处理资产库图片时,请查看可能有助于您提高效果的this answer