开发者

How to check whether the cell has a subview or not in iphone?

I am new to iPhone development. I have a view called barView which is added as the subview to the cell, I want to check for the condition like this

if(cell has a subview barview)
{
do something.......
}else 
{
do something......
} 

How can 开发者_Go百科I check like this?


The simplest way is to give your barview a special tag:

barview.tag = 123221;

and then check with

UIView* barview = [cell viewWithTag:123221];
if (barview != nil) {
  ...
}

Otherwise, you need to iterate through the .subviews array and check if the property matches, e.g.

UIView* barview = nil;
for (UIView* subview in cell.subviews) {
   if ([subview isKindOfClass:[BarView class]]) {
      barview = subview;
      break;
   }
}
if (barview != nil) {
  ...
}


if (barView.superview == cell)
{
   …
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜