2

I am adding subview to UITableViewCell i.e

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault` reuseIdentifier:cellIdentifier];

Here _cellBackgroundView belongs to UIView.

[cell.contentView addSubview:_cellbackground];

I want to check by the help of isDescendantOfView if it contains _cellbackground, but I am getting warning.

if (![_cellbackground isDescendantOfView:[cell subviews]]) {
    [cell.contentView addSubview:_cellbackground];

}
else{
    [_cellbackground removeFromSuperview];
}

references Check if a subview is in a view

Please help

Community
  • 1
  • 1
Joyal Clifford
  • 1,212
  • 11
  • 20

2 Answers2

2

[cell subviews] return array , but you need to give UIView as input parameter for isDescendantOfView: method , try like this it will work

if (![_cellbackground isDescendantOfView:cell.contentView]) {
    [cell.contentView addSubview:_cellbackground];
}
else {
    [_cellbackground removeFromSuperview];
} 
Andriy
  • 2,767
  • 2
  • 21
  • 29
Satyanarayana
  • 1,059
  • 6
  • 16
0

[cell subviews] should be replaced by a object of UIView

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
Flybor
  • 1
  • 1