How to check if cell has subview or not in iphone?

I am new to iphone development. I have a view called barView that is added as a subset to a cell if you want to check a state like this

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

How can I check this, please help me. Thank.

+3
source share
2 answers

The easiest way is to give your tag a barviewspecial tag:

barview.tag = 123221;

and then check the box

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

Otherwise, you need to iterate through the array .subviewsand 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) {
  ...
}
+14
source
if (barView.superview == cell)
{
+3
source

Source: https://habr.com/ru/post/1744602/


All Articles