Search code examples
iosobjective-cuitableviewios7

UITableViewCell subviews returns only UITableViewCellScrollView in iOS7


I have a custom UITableViewCell with 7 subviews. One of them is an activity view, so in order to find it and stop, I do something like this:

NSArray *subviews=[cell subviews];       
NSLog(@"Subviews count: %d",subviews.count);     
for (UIView *view in subviews)  
{                
  NSLog(@"CLASS: %@",[view class]);     
  // code here     
 }

In iOS6 , Subviews count: is 7 and one of them is the activity view. But in iOS7 , the Subviews count: is 1 and [view class] returns UITableViewCellScrollView . Tried, NSArray *subviews=[cell.superview subviews]; and NSArray *subviews=[cell.contentview subviews]; , but in vain.

Any suggestions?


Solution

  • You need to recursively descend into each subview's subviews and so on. Never make any assumptions about the private subview structure. Better yet, since you should only add subviews to the cell's contentView, just look in the contentView, not the whole cell.