2014-01-18 75 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

相關問題