我正在向 UITableViewCell
添加 subview ,即
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault` reuseIdentifier:cellIdentifier];
这里_cellBackgroundView
属于UIView
。
[cell.contentView addSubview:_cellbackground];
我想借助 isDescendantOfView
来检查它是否包含 _cellbackground
,但我收到警告。
if (![_cellbackground isDescendantOfView:[cell subviews]]) {
[cell.contentView addSubview:_cellbackground];
}
else{
[_cellbackground removeFromSuperview];
}
引用文献Check if a subview is in a view
请帮忙
最佳答案
[cell subviews]
返回数组,但您需要将 UIView
作为 isDescendantOfView:
方法的输入参数,尝试这样它将工作
if (![_cellbackground isDescendantOfView:cell.contentView]) {
[cell.contentView addSubview:_cellbackground];
}
else {
[_cellbackground removeFromSuperview];
}
关于ios - 如何检查 UITableViewCell 是否包含 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37538974/