sey*_*glu 4 objective-c ios ios7
下面的代码在IOS 5.0,6.0,6.1等上返回"YES",但在IOS 7.0上返回"NO".窦你对此有所了解吗?这是IOS 7.0的错误吗?非常感谢..
[view isKindOfClass:[SimpleLabel class]]
Run Code Online (Sandbox Code Playgroud)
PS:"SimpleLabel"是一个继承自UILabel的类.
---- ----更新
对不起,问题不明确.:(我在UITableViewCell上课时使用上面的代码,并添加SimpleLabel如下;
[self addSubview:label];
Run Code Online (Sandbox Code Playgroud)
我重写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;
Run Code Online (Sandbox Code Playgroud)
UITableViewCell在iOS 7中,视图层次结构略有改变
在iOS <= 6中,层次结构看起来像
<UITableViewCell>
| <UITableViewCellContentView>
| | <UILabel>
Run Code Online (Sandbox Code Playgroud)
而在iOS 7中它就像
<UITableViewCell>
| <UITableViewCellScrollView>
| | <UIButton>
| | | <UIImageView>
| | <UITableViewCellContentView>
| | | <UILabel>
Run Code Online (Sandbox Code Playgroud)
(来源:http://www.curiousfind.com/blog/646)
添加子视图时,它会插入到UITableViewCellContentView比您要查找的位置更深的位置.
isKindOfClass: 工作正常,问题是你正在经历错误的子视图集.
顺便说一下,这是一个很好的例子,说明为什么你不应该依赖内部视图层次结构:Apple可以随时更改它们.
| 归档时间: |
|
| 查看次数: |
2042 次 |
| 最近记录: |