简体   繁体   中英

How to hide the height of the Particular cell height in uitableview

How to hide a lable in the uitableviewcell when a button is clicked?

I have labels and button in tableviewcell when i click on that particulars cell button that cells height should decrease and as well as that cells label should be hidden.

enter code here

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath
   {
   UIWebView *webView=(UIWebView*)[cell.contentView viewWithTag:999+indexPath.row];
    if(webView==nil)
    {

     webView =[[UIWebView alloc]initWithFrame:CGRectMake(100, 50, 700, 100)];
    [webView loadHTMLString:[text_Array objectAtIndex:indexPath.row] baseURL:nil];
    webView.backgroundColor=[UIColor clearColor];
    [cell.contentView addSubview:webView];
    webView.tag=indexPath.row+999;

    int hideWeb=[[webHideArr objectAtIndex:indexPath.row]intValue];
    if(hideWeb==1)
    {
        webView.hidden=YES;
    }
    else           
    {
        webView.hidden=NO;
    }
    }
   }

  -(void)reviewedCustomButtonClicked:(id)sender
   {
int irow=[sender tag]-222;

UITableViewCell *Cell=(UITableViewCell*)[progressTableView cellForRowAtIndexPath:    [NSIndexPath indexPathForRow:irow inSection:0]];

UIWebView *web=(UIWebView*)[Cell.contentView viewWithTag:irow+999];
isCustomReviewed=YES;

[webHideArr removeAllObjects];
for(int h=0;h<[array count];h++)
{
    [webHideArr addObject:@"0"];
}

if([btn currentImage]!=[UIImage imageNamed:@"arrow_up.png"])
{
    [btn setImage:[UIImage imageNamed:@"arrow_up.png"] forState:UIControlStateNormal];
    web.hidden=YES;
     [imgArr replaceObjectAtIndex:irow withObject:@"1"];
    [webHideArr replaceObjectAtIndex:irow withObject:@"1"];

}
else
{
    [btn setImage:[UIImage imageNamed:@"arrow_dwn.png"] forState:UIControlStateNormal];
    web.hidden=NO;
    [imgArr replaceObjectAtIndex:irow withObject:@"0"];
    [webHideArr replaceObjectAtIndex:irow withObject:@"1"];
}

increseCellHeight=[sender tag]-222;
decreaseCellHeight=[sender tag]-222;
[progressTableView reloadData];
 }

       - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
   {
    if(isCustomReviewed==YES)
     { 
         if (indexPath.section == 0 && indexPath.row == increseCellHeight)
        {

            return 150;
        }
        else
        {
            return 50;
        }
    }

You need to reload table view ([tableView reloadData]) when you click on button with updated height & hiding the label in

  • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

Method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM