gpt4 book ai didi

ios - 如何检查 UITableViewCell 是否包含 UIView

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:30:56 24 4
gpt4 key购买 nike

我正在将 subview 添加到 UITableViewCell

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com