tags:

views:

15

answers:

1

Hi, I want to hide custom button present in tableview cell for a specific condition.

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath 
 {
     if(isDisplayMapbutton==YES)
   {                           
         UIView* buttonView1 = [[UIView alloc] init];
         mapBtn= [[MyCustomButton alloc] initWithIndexPath:indexPath];
         CGRect imageFrame1 = CGRectMake(0,2.0,30,30);  
         [buttonView1 setFrame: CGRectMake(230,3.0,30,30 ) ];
         [mapBtn setFrame:imageFrame1];
         [mapBtn setBackgroundImage: [UIImage imageNamed:@"Map.png"] forState:UIControlStateNormal];
         [mapBtn addTarget:self  action:@selector(DisplayMap:)forControlEvents:UIControlEventTouchUpInside];

         [buttonView1 addSubview:mapBtn];
         [cell.contentView addSubview:buttonView1];
         [buttonView1 release];

        [mapBtn release];
    }
    else        
    {

    }
  return cell;
}

-(void)toggleMove
  {
     if(isMove==YES)
     {
        isDisplayMapbutton  =NO;

        isMove=NO;
        //mapBtn.hidden=YES;
        [self getToolbar];
    }
    else
    {
        isDisplayMapbutton =YES;
     isMove=YES;
     //mapBtn.hidden=NO;

         [self getToolbar];
    }
    [tableView reloadData];
    [self.tableView setEditing:!self.tableView.editing animated:YES];
}

If I use the above method ,[self.tableView setEditing:!self.tableView.editing animated:YES]; the cell will be compressed. then map btn is moving to the end of cell. HOW to hide this Map
button when we call the above method

+1  A: 

Right after you release mapBtn, do something like this

mapBtn = (MyCustomButton *) [cell.contentView viewWithTag: 1];

and also place this after the mapBtn method calls

mapBtn.tag = 1;
Alexsander Akers
Good answer but you should explain what the tag is and how you are using it.
gcamp
The tag is to distinguish this subview from the other ones. It's a simple way to obviously tell one from another.
Alexsander Akers