- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 UITableViewCell,我在其中添加一个 UIView
并在其中添加 subview ,如 UIButton
、UIImageView
。
现在我想访问 willDisplayCell
中的 UIView。为此,我在下面。
NSArray *subviews;
subviews = cell.subviews;
int xxyyzz = 1;
for(id aView in subviews) {
NSLog(@"aView====%@" , [UIView class]);
if([aView isKindOfClass:[UIView class]]) {
NSLog(@"This is UIView... Do what you want to do...");
}
}
但是当我运行时,我得到 This is UIView... Do what you want to do...
用于所有 subview (即 UIButton、UIImageView 等)。 aView====UIView
我相信这是因为 UIView 是所有对象的父类(super class)。
UITableViewCell
中的 UIView...最佳答案
我没有完全理解你的问题,但可能在使用方法 -isKindOfClass
时存在误解。特别是该方法对类和子类响应 YES,UIButton
、UITableView
等是 UIView
的子类,因此该方法按预期工作,这里是文档:
Returns a Boolean value that indicates whether the receiver is an instance of given class or an instance of any class that inherits from that class.
您很可能想使用 -isMemberOfClass
,它只考虑对象是否是特定类的实例。
如果您正在检查的对象来自类集群,例如 NSArray
,您还必须注意使用该方法,引用 Apple 文档:
Be careful when using this method on objects represented by a class cluster. Because of the nature of class clusters, the object you get back may not always be the type you expected. If you call a method that returns a class cluster, the exact type returned by the method is the best indicator of what you can do with that object. For example, if a method returns a pointer to an NSArray object, you should not use this method to see if the array is mutable, as shown in the following code:
// DO NOT DO THIS! if ([myArray isKindOfClass:[NSMutableArray class]])
{
// Modify the object
}
If you use such constructs in your code, you might think it is alright to modify an object that in reality should not be modified. Doing so might then create problems for other code that expected the object to remain unchanged.
If the receiver is a class object, this method returns YES if aClass is a Class object of the same type, NO otherwise.
关于ios - [myView isKindOfClass :[UIView class]] giving weird result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26817197/
如何确定结构是否属于特定类型?换句话说,如果我得到一个对象,我怎么知道底层类型是一个结构体? +(BOOL)isPrimitive:(id)input { return [input isKi
我有一个方法someMethod。此方法在某些时候具有以下 if-else 条件。 - (void) someMethod { // ... some more code ... if
我只想抓取ScrollView中的按钮标签1~5,其他数据不需要抓取 (void)layoutScrollImages { UIImageView *view = nil; NSArr
我有一个无法理解的问题,我正在使用一个用于使用Map Open Source Map(https://github.com/route-me/route-me)的库,该示例运行完美,并且我相信不是与代
我原以为这是一个身份,但它现在似乎对我不起作用。 看我的 lldb 提示符: po [self class] ==> MyCustomClass po [MyCustomClass 类] ==> My
最新版本的 Objective-C 和 XCode (4.4)。 我有一个代码片段,我不明白为什么我可以使用一些行,让我解释一下: // For understanding purpose : (NS
我创建了一个自定义类AnimalView,它是UIView的子类,包含一个UILabel和一个UIImageView >。 @interface AnimalView : UIView { U
我正在检查 toViewController(我的 tabBar 中的第二个选项卡)是否属于 MatchCenterViewController 类,但是 else 语句正在运行,这告诉我它不属于那个
我有一个 ViewController 和一些供用户输入的标签和文本字段,在某些时候我需要遍历所有文本字段以收集用户的输入。 override func viewDidLoad() { sup
我有一个与 Cocoapods (ECSlidingViewController) 一起安装的库。在代码中,比较是使用 -isKindOfClass 完成的。在调试器中,打印描述和一切都表明这个变量是
有没有比更好的方法来查看一个对象是否具有多个类之一 if ([item isKindOfClass:[NSArray class]] || [item isKindOfClass:[NSNumber
引用下面的代码,我发现 isKindOfClass 无法识别类。 id parent = [self.tableDataSource objectAtIndex:indexPath.row]; //p
出于各种原因,为了使数组的索引与其他事物保持一致,我在数组中加入了[NSNull null]。像这样: NSArray *arr = @[obj1, obj2, obj3, [NSNull null]
有人可以解释为什么 isKindOfClass 会根据实例的创建方式返回不同的结果吗? @interface BaseClass ... @interface DerivedClassA : Base
我的一个单元测试失败了,原因出乎我的意料。似乎对 isKindOfClass 的调用返回了 NO,但是当我调试并单步执行时,似乎没有理由返回 NO。 代码是: if ([self.detailItem
我正在做一个 iOS5+ 项目(xcode 4.4.1 SDK 5.1) 我在单元测试中有这段代码: [_appDelegate application:nil didFinishLaunchingW
Swift 提供了is 关键字(和as?)来检查一个对象是否可以成功向下转型: if foo is MyClass { // ... } 但是NSObjectProtocol也提供了原来的fu
Swift 中的 isKind(of aClass: AnyClass) 和 isMember(of aClass: AnyClass) 函数有什么区别? Objective-C 中的原始问题 Wha
最近升级了 XCode8 我在 isKindOfClass 中遇到问题这段代码一直有效到 iOS9 的方法但在 iOS10突然[items isKindOfClass: [NSMutableArray
我有以下代码来根据 rvc 的类型确定不同的操作: let rvc = UIApplication.sharedApplication().delegate.window?.rootViewCont
我是一名优秀的程序员,十分优秀!