[英]isKindOfClass does not work as expected IOS 7
下面的代碼在IOS 5.0,6.0,6.1等上返回“YES”,但在IOS 7.0上返回“NO”。 竇你對此有所了解嗎? 這是IOS 7.0的錯誤嗎? 非常感謝..
[view isKindOfClass:[SimpleLabel class]]
PS:“SimpleLabel”是一個繼承自UILabel的類。
---- ----更新
對不起,問題不明確。 :(我在UITableViewCell
類中使用上面的代碼,並添加SimpleLabel
如下;
[self addSubview:label];
我覆蓋了layoutSubviews
函數,在self.subviews
循環,但[view class]
總是返回UITableViewCellScrollView
。
-(void)layoutSubviews {
[super layoutSubviews];
for (UIView*view in self.subviews) {
if ([view isKindOfClass:[SimpleLabel class]]) {
SimpleLabel*label = (SimpleLabel*)view;
UITableViewCell
的視圖層次結構在iOS 7中略有改變
在iOS <= 6中,層次結構看起來像
<UITableViewCell>
| <UITableViewCellContentView>
| | <UILabel>
而在iOS 7中它就像
<UITableViewCell>
| <UITableViewCellScrollView>
| | <UIButton>
| | | <UIImageView>
| | <UITableViewCellContentView>
| | | <UILabel>
(來源: http : //www.curiousfind.com/blog/646 )
添加子視圖時,它會插入到UITableViewCellContentView
,該視圖比您要查找的位置深一層。
isKindOfClass:
工作正常,問題是你正在經歷錯誤的子視圖集。
順便說一下,這是一個很好的例子,說明為什么你不應該依賴內部視圖層次結構:Apple可以隨時更改它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.