0

Here is some interesting question .I am developing an app with tableview. Initially tableview is having 4 rows and all the 4 rows having same images in image views. When i click first row i manually added some sub rows under first row and reloaded the table view. When i second click on same row that i previously clicked i removed the objects that i added manually and reloading tableview. I want to change image for 1 st. row when 1 st. row is clicked and second click on 1 st. row then showing previous image same for all the four rows ..please tell me how to do this.

a=b=c=FALSE


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

{

    ///////11111

if(a==FALSE && indexPath.row==0)

{

 [array insertObject:@"a" atIndex:1];

  [array insertObject:@"b" atIndex:2];

 [array insertObject:@"c" atIndex:3];

a=TRUE;


}

   else if(indexPath.row==0 && a==TRUE)

 {

 [array removeObject:@"a"];

  [array removeObject:@"b"];

  [array removeObject:@"c"];


        a=FALSE;
    }


 else if(a==FALSE && b==FALSE && indexPath.row==1)


    {
        [array insertObject:@"d" atIndex:2];
          [array insertObject:@"e" atIndex:3];
          [array insertObject:@"f" atIndex:4];
        b=TRUE;
    }
    else if(a==TRUE && b==FALSE && indexPath.row==4)
    {
        [array insertObject:@"d" atIndex:5];
        [array insertObject:@"e" atIndex:6];
        [array insertObject:@"f" atIndex:7];
        b=TRUE;
    }
    else if(a==FALSE && b==TRUE && indexPath.row==1)
    {
        [array removeObject:@"d"];
        [array removeObject:@"e"];
        [array removeObject:@"f"];
        b=FALSE;
    }
    else if(a==TRUE && b==TRUE && indexPath.row==4)
    {
        [array removeObject:@"d"];
        [array removeObject:@"e"];
        [array removeObject:@"f"];
        b=FALSE;
    }



    /////////3333333333

    else if(a==FALSE && b==FALSE && c==FALSE && indexPath.row==2)
    {
        [array insertObject:@"m" atIndex:3];
        [array insertObject:@"n" atIndex:4];
        [array insertObject:@"p" atIndex:5];
        c=TRUE;
    }
    else if(a==FALSE && b==TRUE && c==FALSE && indexPath.row==5)
    {
        [array insertObject:@"m" atIndex:6];
        [array insertObject:@"n" atIndex:7];
        [array insertObject:@"p" atIndex:8];
        c=TRUE;
    }
    else if(a==TRUE && b==FALSE && c==FALSE && indexPath.row==5)
    {
        [array insertObject:@"m" atIndex:6];
        [array insertObject:@"n" atIndex:7];
        [array insertObject:@"p" atIndex:8];
        c=TRUE;
    }
    else if(a==TRUE && b==TRUE && c==FALSE && indexPath.row==8)
    {
        [array insertObject:@"m" atIndex:9];
        [array insertObject:@"n" atIndex:10];
        [array insertObject:@"p" atIndex:11];
        c=TRUE;
    }


        else if(a==TRUE && b==TRUE && c==TRUE && indexPath.row==8)
        {
            [array removeObject:@"m"];
             [array removeObject:@"n"];
             [array removeObject:@"p"];
            c=FALSE;
        }
        else if(a==TRUE && b==FALSE && c==TRUE && indexPath.row==5)
        {
            [array removeObject:@"m"];
            [array removeObject:@"n"];
            [array removeObject:@"p"];
            c=FALSE;
        }
        else if(a==FALSE && b==TRUE && c==TRUE && indexPath.row==5)
        {
            [array removeObject:@"m"];
            [array removeObject:@"n"];
            [array removeObject:@"p"];
            c=FALSE;
        }
    else if(a==FALSE && b==FALSE && c==TRUE && indexPath.row==2)
    {
        [array removeObject:@"m"];
        [array removeObject:@"n"];
        [array removeObject:@"p"];
        c=FALSE;
    }


    //////4444444444
    if(indexPath.row==[array count]-1)
    {
      ---
    }

    [tableview reloadData];
}
4

2 回答 2

1

我假设您正在使用包含字典的数组填充表格视图。您可以在字典中设置一个标志(类似于“扩展”或“折叠”),然后在 cellForRowAtIndexPath 中检查该标志是否为真/假,以便您可以根据该标志设置图像。

于 2012-05-24T07:59:36.060 回答
0

创建具有类型单元格的类,该类具有单元格上的数据成员和另一个类型为 NSString *parentElement 的数据成员。对于主要的四个标签,父元素将为空。但对于单元格内的子单元格,所有者单元格将是其父元素。所以现在检查父元素的条件并设置您想要的图像。它对我来说很好。希望它也对你有用。

于 2012-05-24T10:18:57.907 回答