IsKindOfClass not working properly iOS 7

The code below returns β€œYES” in iOS 5.0, 6.0, 6.1, etc., but returns β€œNO” in iOS 7.0. Do you have any idea about this? Is this an iOS 7.0 bug? Many thanks..

[view isKindOfClass:[SimpleLabel class]] 

PS: "SimpleLabel" is a class inherited from UILabel.

---- UPDATE ----

Sorry for the incomprehensible question. :( I use the code above in the UITableViewCell class and add SimpleLabel , as shown below:

  [self addSubview:label]; 

I override the layoutSubviews function, the loop in self.subviews , but the [view class] always returns a UITableViewCellScrollView .

 -(void)layoutSubviews { [super layoutSubviews]; for (UIView*view in self.subviews) { if ([view isKindOfClass:[SimpleLabel class]]) { SimpleLabel*label = (SimpleLabel*)view; 
+4
source share
1 answer

UITableViewCell view hierarchy has changed a bit in iOS 7

On iOS <= 6, the hierarchy looks like

 <UITableViewCell> | <UITableViewCellContentView> | | <UILabel> 

whereas in iOS 7 it looks like

 <UITableViewCell> | <UITableViewCellScrollView> | | <UIButton> | | | <UIImageView> | | <UITableViewCellContentView> | | | <UILabel> 

(source: http://www.curiousfind.com/blog/646 )

When you add a subview, it is inserted into the UITableViewCellContentView , which is one level deeper than where you are looking.

isKindOfClass: working correctly, the problem is that you are going through the wrong set of subheadings.

By the way, this is a great example of why you should never rely on internal hierarchies of views: Apple can change them at any time.

+7
source

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


All Articles