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];
}
5
  • show us your interesting code ;) Commented May 24, 2012 at 7:59
  • You need to clear your concept about sections in UITableview to solve your query. Its more interesting than your question Commented May 24, 2012 at 8:00
  • you can't add subrows ..the indexpath will change for each row added..do you have a custom cell which is mischeviously behaving as subRows? Commented May 24, 2012 at 8:03
  • hi guys i added my code plz go through it you will ghet an idea Commented May 24, 2012 at 8:53
  • I am damn sure , you need to use Sections in UITableview it will need much less effor than this. Commented May 24, 2012 at 9:02

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

no rick i am not added dictionary. I manually added the objects as above plz see the code
You need to change your code to use sections and an array with dictionaries so you can properly keep track on things and thus set a correct image when you want ;)
0

Create class with type cell which having the data members whatever u r having on the cell and another of type NSString *parentElement. For main four labels parent element will be null.But for the subcells inside the cell the owner cell will be its parent element.So now check the conditions for the parent element and set the image that you want. It worked fine for me .Hope it will also work for you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.