Iphone 仅对于特定行,重用表视图单元格的子视图为nil

Iphone 仅对于特定行,重用表视图单元格的子视图为nil,iphone,ios,uitableview,storyboard,Iphone,Ios,Uitableview,Storyboard,我已经尝试解决这个问题很长一段时间了,但我仍然无法解决它。我在story board中有一个自定义的表视图单元格。在单元格中,我添加了6个视图,每个视图都有一个imageView子视图。我设置了视图标签,以便以后可以访问它们。此表在我的应用程序中用作缩略图视图。问题是,在特定行中,最后一个缩略图容器视图不再将imageview作为子视图,从而导致崩溃 下面是我为表格设置图像的代码。任何帮助都将不胜感激。谢谢大家! NSString *CellIdentifier = @"ThumbnailC

我已经尝试解决这个问题很长一段时间了,但我仍然无法解决它。我在story board中有一个自定义的表视图单元格。在单元格中,我添加了6个视图,每个视图都有一个imageView子视图。我设置了视图标签,以便以后可以访问它们。此表在我的应用程序中用作缩略图视图。问题是,在特定行中,最后一个缩略图容器视图不再将imageview作为子视图,从而导致崩溃

下面是我为表格设置图像的代码。任何帮助都将不胜感激。谢谢大家!

  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;
NSString*CellIdentifier=@“ThumbnailCell”;
UITableViewCell*单元格=(UITableViewCell*)[tableView出列重用CellWithIdentifier:CellIdentifier];
//循环浏览每个缩略图

对于(int i=1;i你应该使用新的iOS 6,因为它是为这样的事情而设计的。

搜索一些标准的tableView示例…并遵循它们。.我认为你需要更多地解释你正在尝试做什么。我不明白你尝试做什么以及失败的地方。
cellForRowAtIndexPath:
…为你的
t创建一个数组humbnailImages
然后将此
数组用于
cellImage
。@Rajneesh071这不是我第一次使用表视图,并且此代码除了特定行之外都正常工作,所以可能我遗漏了一些内容。但是无论如何,谢谢。@RickyHelperson我已经编辑了我的问题,希望我能说得更清楚,谢谢!