The code below, returns "YES" on IOS 5.0, 6.0, 6.1 etc. but returns "NO" on IOS 7.0. Dou you have an idea about that? Is it an IOS 7.0 bug? Thanks a lot..
[view isKindOfClass:[SimpleLabel class]]
PS: "SimpleLabel" is a class inherited from UILabel.
----UPDATE----
Sorry for unclear question. :(
I use the code above in a UITableViewCell
class, and add SimpleLabel
as below;
[self addSubview:label];
I override layoutSubviews
function, loop in self.subviews
, but [view class]
always returns UITableViewCellScrollView
.
-(void)layoutSubviews {
[super layoutSubviews];
for (UIView*view in self.subviews) {
if ([view isKindOfClass:[SimpleLabel class]]) {
SimpleLabel*label = (SimpleLabel*)view;
UITableViewCell
's view hierarchy changed slightly in iOS 7
In iOS <= 6 the hierarchy looks like
<UITableViewCell>
| <UITableViewCellContentView>
| | <UILabel>
whereas in iOS 7 it's like
<UITableViewCell>
| <UITableViewCellScrollView>
| | <UIButton>
| | | <UIImageView>
| | <UITableViewCellContentView>
| | | <UILabel>
(source: http://www.curiousfind.com/blog/646)
When you add a subview it is inserted in the UITableViewCellContentView
which is one level deeper than where you are looking for.
isKindOfClass:
works properly, the issues is that you are going through the wrong set of subviews.
By the way this is a splendid example of why you should never rely on internal view hierarchies: Apple can change them at any time.
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