views:

174

answers:

2

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

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

How can i check like this, please help me out.Thanks.

+4  A: 

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) {
  ...
}
KennyTM
+1  A: 
if (barView.superview == cell)
{
   …
Adam Wright