可折叠的tableview错误

时间:2014-03-23 08:39:07

标签: ios objective-c uitableview

我有UITableView的这个错误,我用故事板制作了一个原型单元格,并且它可以崩溃,这意味着当你击中单元格时,你会在该主题下获得更多单元格。

该主题下的所有其他单元格都将UIImageView作为侧视图。 发生的事情是,在我第一次点击该主题单元格后,应该只附加到子单元格的图像也附加到主题单元格。

所以,当我点击一个单元格时,我更改了这个数组以了解它的可折叠性:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    //subject hitted
    if (indexPath.row == 0)
    {
        collapsedRows[indexPath.section]= ! collapsedRows[indexPath.section];
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section]withRowAnimation:UITableViewRowAnimationFade];
    }
    }

我告诉表格查看它有多少部分 - 现在它有更多部分,因为它已打开:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    //subject cell is open
    if(collapsedRows[section])

    {
        if([[allAppointments objectAtIndex:section] count]>0)
        {

           NSMutableArray *sectionTime=[allAppointments objectAtIndex:section];

           return [sectionTime count]+1;

        }
        else
            return 1;
    }
    else
        return 1;


}

,重新加载表时,我只将图像附加到非0(=主题)的行

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];



   //labels on the cell
    UILabel *labelBusiness = (UILabel *)[cell viewWithTag:1];
    UILabel *labelTime = (UILabel *)[cell viewWithTag:3];
    UILabel *labelStreet = (UILabel *)[cell viewWithTag:4];
    UIImageView *sideView=(UIImageView*)[cell viewWithTag:6];
    UILabel *labelTitle = (UILabel *)[cell viewWithTag:8];
    labelBusiness.text=@"";
    labelStreet.text=@"";
    labelTime.text=@"";
    labelTitle.text=@"";



    // ONLY WHEN SUBJECT SHOW THE SUBJECT TITLE-NO IMAGE HERE!
    if (indexPath.row==0)
    {

        NSString *title=@"";
        if(indexPath.section==0)
            title=@"PAST";
        else if(indexPath.section==1)
             title=@"TODAY";
        else if(indexPath.section==2)
            title=@"TOMORROW";
        else if(indexPath.section==3)
            title=@"FUTURE";

        labelTitle.text=title;

    }



    //ON THE SUB CELLS ONLY SHOW IMAGES
    else
    {

              //do more stuff here….

               //show images
               if( [allImages count]>0)
               {
                 cell.imageView.layer.masksToBounds = YES;
                 cell.imageView.layer.cornerRadius = 12.0;
                 cell.imageView.image=[[allImages objectAtIndex:indexPath.section] objectAtIndex:indexPath.row-1] ;

               }


           }

    }

    return cell;
}

所以在我第一次打开行并打开子细胞后,关闭它们,从现在开始,图像也附加了主题细胞! 记录不会显示其偶数进入else条件。

1 个答案:

答案 0 :(得分:2)

当单元格从重用队列中出来时,它们中包含所有旧信息。因此,您需要将cell.imageView.image设置为nil,以便在设置subject cell时删除图像。

相关问题