2014-01-18 68 views
0

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

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

你是什么意思的“不能选择细胞”?你有没有实现didSelectRowAtIndexPath? – Mike

回答

1

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

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

注意

当你正在处理的资源库图片,请大家看我的this answer,可以帮助你获得更好的性能。

+0

感谢您的回复。我试图通过IB和程序添加启用用户交互,但它仍然无法工作 – Ced

相关问题