2014-01-18 4 views
0

나는 UIImage과 셀당 제목이 들어있는 UITableView입니다. ALAssetsLibrary을 통해 생성되는 그림의 경로가 포함 된 내 DB에서 이미지를 가져오고 있습니다. 문제는 내가 사진을 테이블에 포함시킬 때마다 셀을 선택할 수 없다는 것입니다. 어떤 도움도 감사 할 것입니다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의 사용자 지정 하위 클래스에서 이벤트를 처리하려는 경우 개체를 초기화 한 후에 속성의 값을 YES으로 명시 적으로 변경해야합니다.

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

:

당신이 자산 라이브러리 이미지 다루고, 더 나은 성능을 위해 당신을 도울 수 내 this answer를보고하십시오.

+0

답장을 보내 주셔서 감사합니다. 나는 IB와 프로그램을 통해 사용자 상호 작용을 가능하게하는 추가를 시도했지만 여전히 작동하지 않습니다. – Ced

관련 문제