English 中文(简体)
设置特定表格单元格的图像视图
原标题:Setting image views for particular table cells

下面是一个有趣的问题。 我正在开发一个与表视图有关的应用程序。 最初的表视图在图像视图中有4行和所有4行都有相同的图像。 当我单击第一行时, I手动在第一行下添加了一些子行, 并重新装入了表格视图。 当我在同一个行上点击之前我先单击的第二行时, 我删除了我手动添加和重新装入表视图的对象。 我想在单击 1 st. 列时更改 1 st. 列的图像, 在 1 st. 列上第二次单击, 然后显示所有四个行的先前图像相同 。 请告诉我如何这样做 。

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];
}
最佳回答

I assume you are filling the table view with an array that has dictionaries. You could set a flag into a dictionary (something like expanded or collapsed ) and then check if the flag is true/false in cellForRowAtIndexPath so that you can set an image according to the flag.

问题回答

使用类型单元格创建类, 该类型单元格拥有数据成员, 无论单元格和另一种类型 NSString *colentElement 的数据成员。 对于主 4 标签父元素将无效。 但对于单元格内的子单元格来说, 所有者单元格将是其父元素。 所以现在检查父元素的条件, 并设置您想要的图像。 它对我有效。 希望它也能为您工作 。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签