remove the subviews from the contentView of UITableViewCell (reset the UITableView)

后端 未结 9 944
遥遥无期
遥遥无期 2020-12-23 15:29

Any idea on how to reset a UITableView?

I want to display a new set of data at the press of a button and also remove all the subviews from the cell\'s

相关标签:
9条回答
  • 2020-12-23 16:08
    for subview in cell.contentView.subviews {
        subview.removeFromSuperview()
    }
    
    0 讨论(0)
  • 2020-12-23 16:12

    Better yet, when you create the cell:

    #define MY_CUSTOM_TAG 1234
    mySubview.tag = MY_CUSTOM_TAG;
    [cell.contentView addSubview:mySubview] ;
    

    And later on, when you need to remove it:

    [[cell.contentView viewWithTag:MY_CUSTOM_TAG]removeFromSuperview] ;
    
    0 讨论(0)
  • 2020-12-23 16:12

    I got the answer :)

    if ([cell.contentView subviews]) {
        for (UIView *subview in [cell.contentView subviews]) {
            [subview removeFromSuperview];
        }
    }
    

    This piece of code will check if the cell's content view has any subviews.
    If there are any, it removes them as the for loop iterates!

    0 讨论(0)
提交回复
热议问题