2016-05-31 55 views
3

我添加子视图UITableViewCell如何检查的UITableViewCell包含的UIView

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

请帮

+0

你说你正在接受警告。警告说什么? – Niko

回答

2

[cell subviews]返回数组,但你需要给UIView作为输入参数为isDescendantOfView:方法,尝试这样它会工作

if (![_cellbackground isDescendantOfView:cell.contentView]) { 
    [cell.contentView addSubview:_cellbackground]; 
} 
else { 
    [_cellbackground removeFromSuperview]; 
} 
0

[cell subviews]应该由的对象替换10