저는이 문제를 지금 당분간 해결하려고 노력하고 있으며 아직 해결할 수 없습니다. 내가 가지고있는 것은 스토리 보드에서 사용자 정의 테이블 뷰 셀입니다. 셀에는 6 개의 뷰가 추가되었으며 각 뷰에는 imageView 하위 뷰가 있습니다. 나중에 뷰에 액세스 할 수 있도록 뷰의 태그를 설정합니다. 이 테이블은 내 앱에서 미리보기로 사용됩니다. 문제는 특정 행에서 마지막 썸네일 컨테이너보기가 하위보기로 이미지보기를 더 이상 발생시키지 않아 충돌이 발생한다는 것입니다.재사용 된 테이블 뷰 셀의 서브 뷰는 특정 행에 대해서만 nil입니다.
다음은 테이블의 이미지를 설정하는 코드입니다. 어떤 도움이라도 대단히 감사하겠습니다. 고맙습니다!
NSString *CellIdentifier = @"ThumbnailCell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//loops through each thumbnails
for (int i=1; i<=kNumberOfThumbnails; i++)
{
//get index of current thumbnail- starting value is 0
int index=((indexPath.row *kNumberOfThumbnails)+i)-1;
NSLog(@"index %d",index);
//create an indexpath given the computed index and cell section
NSIndexPath *currentIndexPath=[NSIndexPath indexPathForRow:index inSection:indexPath.section];
//get number of sections
NSArray *sections = [self.fetchedResultsController sections];
NSInteger count=0;
id <NSFetchedResultsSectionInfo> sectionInfo = [sections objectAtIndex:indexPath.section];
//get number of objects for given section
count = [sectionInfo numberOfObjects];
NSLog(@" i: %d number of subviews ni thumn container %d",i,thumbContainer.subviews.count);
//get view container for thumbnails
UIView *thumbContainer=(UIView *)[cell.contentView viewWithTag:i];
UIImageView *imageView=[thumbContainer.subviews objectAtIndex:0];// this is where the app crashes.. thumbContainer no longer have a subview (for a specific row only)so it throws out an nsrangeexception
if (index<count)
{
//get file using the created indexpath
File *imageFile=[self.fetchedResultsController objectAtIndexPath:currentIndexPath];
//set image
imageView.image=[UIImage imageNamed:imageFile.thumbnail];
thumbContainer.backgroundColor=[UIColor grayColor];
//set tag for image view for the system to know what file is tapped
imageView.tag=(currentIndexPath.section*kImageTagMultiplier)+currentIndexPath.row;
//add tap gesture to thumbnail container view
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resultTapped:)];
tap.numberOfTapsRequired=1;
[thumbContainer addGestureRecognizer:tap];
}
else {
imageView.image=[UIImage imageNamed:@""];
thumbContainer.backgroundColor=[UIColor clearColor];
for (UIGestureRecognizer *gest in thumbContainer.gestureRecognizers) {
[thumbContainer removeGestureRecognizer:gest];
}
}
return cell;
내가 여기하려고 노력하고있어 나는 개체의 배열을 가지고 있으며 각 개체가 썸네일 이미지로 표현된다, 나는이 작은 이미지를 보여주기 위해있는 tableview를 사용 .. 각 행에 대해이 고정 된 썸네일 수. 스토리 보드에는 6 개의 정사각형 뷰가 있고 각 뷰에는 내부에 이미지 뷰가있는 셀이 있습니다. 이유는 그냥 컨테이너 뷰를 추가하는 대신 각 축소판을 tappable이며 내가 tapgesture의 뷰 (컨테이너 뷰) 서브 뷰 (이미지 뷰) 태그를 가져 와서 어떤 개체가 도청되는지 알아야한다는 것입니다.
은 그런데, 나는이 같은 것들을 위해 설계로 내가 충돌을
일부 표준 표보기 예를 들어 .... 따르십시오 .. – Rajneesh071
나는 당신이 무엇을하려고하는지 더 설명해야한다고 생각합니다. 나는 당신이하려고하는 것과 실패한 것을 이해하지 못합니다. –
'cellForRowAtIndexPath의 코드가 많습니다 : .... ....'thumbnailImages'의 배열을 만들고'cellImage'에이 배열을 사용하십시오 ... – TheTiger