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?
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.
I think you should add a conditional statement to your code:
NSArray *subviews;
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
subviews = aCell.contentView.subviews;
else
subviews = aCell.subviews;
for(id aView in subviews) {
if([aView isKindOfClass:[aField class]]) {
//your code here
}
}
//don't forget to add a conditional statement even on adding your subviews to cell
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
[aCell.contentView addSubview:aField];
else
[aCell addSubview:aField];
This is the define for the above SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO macro:
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With