【问题标题】:check condition doesn't work and returning unrecognized selector检查条件不起作用并返回无法识别的选择器
【发布时间】:2012-12-11 19:26:00
【问题描述】:

“if”条件在第一个循环中有效,但在第二个循环中无效 我不明白为什么它不想在第二个循环中检查我的状况以及为什么它只在第一个循环中起作用

for (UIView *view in dro.subviews) {
    for (TOJDropableButtonView *v in view.subviews) {
        if ([v.type isEqualToString:targetView.filterItem.searchFilterItem.type]){
            NSLog(@"%@", targetView.filterItem.searchFilterItem.type);
        }
    }
}


-[UIImageView type]: unrecognized selector sent to instance 0x161bb960
2012-12-11 20:18:00.985 HungryNow[2507:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView type]: unrecognized selector sent to instance 0x161bb960'
*** First throw call stack:
(0x1790012 0x149de7e 0x181b4bd 0x177fbbc 0x177f94e 0x1f401 0x2fe45 0x2ec6c 0x14b1705 0x4f2f4c 0x4f2fbc 0x41833f 0x418552 0x3f63aa 0x3e7cf8 0x27f2df9 0x27f2ad0 0x1705bf5 0x1705962 0x1736bb6 0x1735f44 0x1735e1b 0x27f17e3 0x27f1668 0x3e565c 0x24ad 0x23d5)
libc++abi.dylib: terminate called throwing an exception

【问题讨论】:

    标签: objective-c ios uiview uiimageview subview


    【解决方案1】:

    您正在将所有子视图投射到 TOJDropableButtonView。

    但实际上,dro 有一些不属于 TOJDropableButtonView 类的子视图。 dro 的子视图之一恰好是一个图像视图,它没有“类型”属性,您试图在 equalToString 行中访问它。

    确保您感兴趣的子视图属于 TOJDropableButtonView 类,而不是将所有子视图类型转换为 TOJDropableButtonView。

    下面的代码应该可以解决您的问题。

    for (UIView *view in dro.subviews) {
        for (UIView *v in view.subviews) {
            if([v isKindOfClass:[TOJDropableButtonView class]]){
                if ([v.type isEqualToString:targetView.filterItem.searchFilterItem.type]){
                   NSLog(@"%@", targetView.filterItem.searchFilterItem.type);
                }
            }
        }
    }
    

    【讨论】:

    • 希望您了解崩溃的位置/原因 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-13
    • 2014-06-19
    • 1970-01-01
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多