CodeGuy
CodeGuy

Reputation: 28907

Remove a subview from a UITableViewCell's content view

How do I remove a Subview from a UITableViewCell's content view?

For instance, I have added the following subview to my cell's content view.

UIButton *b = etc.
[cell.contentView addSubview:b];

Now I'd like to remove it: ?

Upvotes: 2

Views: 6244

Answers (2)

Uladzimir
Uladzimir

Reputation: 3486

One line

[cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

Upvotes: 0

Dilip
Dilip

Reputation: 256

This code remove all subviews on cell:

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

Upvotes: 12

Related Questions