Iphone 已将无法识别的选择器发送到实例0xa7ac9a0

Iphone 已将无法识别的选择器发送到实例0xa7ac9a0,iphone,objective-c,ios7,Iphone,Objective C,Ios7,我正在制作一款与iOS7兼容的iPad应用程序。该应用程序在iOS 6中运行完美,但在iOS 7中崩溃 if ([self.exercise.variant isEqualToString:kVariantGFTextItem]) { NSLog(@"item:%@",[[[itemArray objectAtIndex:0] superview]superview]); GapsFillItem *itemView = (GapsFillIt

我正在制作一款与iOS7兼容的iPad应用程序。该应用程序在iOS 6中运行完美,但在iOS 7中崩溃

if ([self.exercise.variant isEqualToString:kVariantGFTextItem]) {

            NSLog(@"item:%@",[[[itemArray objectAtIndex:0] superview]superview]);

            GapsFillItem *itemView = (GapsFillItem*)[[[[itemArray objectAtIndex:0] superview]superview]subviews];
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
            {
                itemView = (GapsFillItem*)[[[itemArray objectAtIndex:0] superview]superview];
            }

            [itemView.buttonPlaySound setImage:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)?kImageButtonSoundPerItemPad:kImageButtonSoundPerItemPhone forState:UIControlStateNormal];
            itemView.buttonPlaySound.userInteractionEnabled = YES;
        }
这段代码在iOS 6中运行得很好,但在iOS 7中却不是

以下是崩溃日志:

    2013-10-19 09:41:53.208 Elementary[645:a0b] item:<TextViewWithTextField: 0xa9e3800; baseClass = UITextView; frame = (183 -10; 562 92); text = 'Hello. Can I  +change+   ...'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0xa7a8170>; layer = <CALayer: 0xa7a7ef0>; contentOffset: {0, 0}>
2013-10-19 09:41:53.209 Elementary[645:a0b] -[__NSArrayM buttonPlaySound]: unrecognized selector sent to instance 0xa7ac9a0
2013-10-19 09:41:53.212 Elementary[645:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM buttonPlaySound]: unrecognized selector sent to instance 0xa7ac9a0'
*** First throw call stack:
(
    0   CoreFoundation                      0x02a435e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x027178b6 objc_exception_throw + 44
    2   CoreFoundation                      0x02ae0903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x02a3390b ___forwarding___ + 1019
    4   CoreFoundation                      0x02a334ee _CF_forwarding_prep_0 + 14
    5   Elementary                          0x00066185 -[GapsFill checkAnswers] + 4693
    6   Elementary                          0x00011bd4 -[ParentViewController checkToolMenuItemTapped] + 228
    7   Elementary                          0x0002da45 -[ToolsMenu menuItemTapped:] + 565
    8   libobjc.A.dylib                     0x02729874 -[NSObject performSelector:withObject:withObject:] + 77
    9   UIKit                               0x00f1dc8c -[UIApplication sendAction:to:from:forEvent:] + 108
    10  UIKit                               0x00f1dc18 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    11  UIKit                               0x010156d9 -[UIControl sendAction:to:forEvent:] + 66
    12  UIKit                               0x01015a9c -[UIControl _sendActionsForEvents:withEvent:] + 577
    13  UIKit                               0x01014d4b -[UIControl touchesEnded:withEvent:] + 641
    14  UIKit                               0x00f5b0cd -[UIWindow _sendTouchesForEvent:] + 852
    15  UIKit                               0x00f5bd34 -[UIWindow sendEvent:] + 1232
    16  UIKit                               0x00f2fa36 -[UIApplication sendEvent:] + 242
    17  UIKit                               0x00f19d9f _UIApplicationHandleEventQueue + 11421
    18  CoreFoundation                      0x029cc8af __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    19  CoreFoundation                      0x029cc23b __CFRunLoopDoSources0 + 235
    20  CoreFoundation                      0x029e930e __CFRunLoopRun + 910
    21  CoreFoundation                      0x029e8b33 CFRunLoopRunSpecific + 467
    22  CoreFoundation                      0x029e894b CFRunLoopRunInMode + 123
    23  GraphicsServices                    0x035b79d7 GSEventRunModal + 192
    24  GraphicsServices                    0x035b77fe GSEventRun + 104
    25  UIKit                               0x00f1c94b UIApplicationMain + 1225
    26  Elementary                          0x00002285 main + 181
    27  Elementary                          0x000021c5 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
2013-10-19 09:41:53.208初级[645:a0b]项目:
2013-10-19 09:41:53.209初等[645:a0b]-[\uu NSArrayM buttonPlaySound]:发送到实例0xa7ac9a0的无法识别的选择器
2013-10-19 09:41:53.212初等[645:a0b]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[\uu NSArrayM buttonPlaySound]:未识别的选择器发送到实例0xa7ac9a0'
***第一次抛出调用堆栈:
(
0 CoreFoundation 0x02a435e4例外预处理+180
1 libobjc.A.dylib 0x027178b6 objc_异常_抛出+44
2 CoreFoundation 0x02ae0903-[NSObject(NSObject)不识别选择器:+275
3 CoreFoundation 0x02a3390b\uuuuuuuuuuuuuuuuuuu+1019
4 CoreFoundation 0x02a334ee\u CF\u转发\u准备\u 0+14
5基本0x00066185-[GapsFill检查答案]+4693
6基本0x00011bd4-[ParentViewController检查工具菜单项]+228
7基本0x0002da45-[工具菜单菜单项:][565
8 libobjc.A.dylib 0x02729874-[NSObject性能选择器:withObject:withObject:+77
9 UIKit 0x00f1dc8c-[UIApplication sendAction:to:from:forEvent:][108
10 UIKit 0x00f1dc18-[UIApplication sendAction:toTarget:fromSender:forEvent:][61
11 UIKit 0x010156d9-[UIControl发送操作:发送到:forEvent:+66
12 UIKit 0x01015a9c-[UIControl\u发送操作预防:带事件:][577
13 UIKit 0x01014d4b-[UIControl触摸已终止:带事件:][641
14 UIKit 0x00f5b0cd-[UIWindow\u sendTouchesForEvent:+852
15 UIKit 0x00f5bd34-[UIWindow sendEvent:+1232
16 UIKit 0x00f2fa36-[UIApplication sendEvent:+242
17 UIKit 0x00f19d9f_UIU应用程序手柄VENTQUEUE+11421
18 CoreFoundation 0x029cc8af\uuuu CFRUNLOOP\u正在调用\uu OUT\uu以执行\uu功能\uuuu+15
19 CoreFoundation 0x029cc23b__CFRunLoopDoSources0+235
20 CoreFoundation 0x029e930e__CFRunLoopRun+910
21 CoreFoundation 0x029e8b33 CFRunLoopRunSpecific+467
22 CoreFoundation 0x029e894b CFRUNLOOPSRUNINMODE+123
23图形服务0x035b79d7 GSEventRunModal+192
24图形服务0x035b77fe GSEventRun+104
25 UIKit 0x00f1c94b UIApplicationMain+1225
26基本0x00002285主+181
27基本0x000021c5启动+53
)
libc++abi.dylib:以NSException类型的未捕获异常终止

如果有人知道为什么会这样,请告诉我。请告诉我。

您的
项目视图
,看起来您希望它是
GapsFillItem
类型,实际上是
NSArray
类型

您之所以知道这一点,是因为崩溃报告告诉您,
NSArray
无法识别名为
buttonlaysound
的选择器,我假设它是在
GapsFillItem
类中定义的

我建议在其中加入一些
NSLog
语句,以了解
itemView
如何成为
NSArray

总的来说,像这样的行是非常可疑的:

GapsFillItem *itemView = (GapsFillItem*)[[[[itemArray objectAtIndex:0] superview]superview]subviews];

itemView = (GapsFillItem*)[[[itemArray objectAtIndex:0] superview]superview];
这两条线之一就是问题所在。我建议避免通过调用superview、superview、SubView等访问对象。如果需要通过这种链访问对象,很可能有更好的方法

祝你好运

编辑

乍一看,由于这一行,iPad上的这一功能似乎总是会崩溃:

GapsFillItem *itemView = (GapsFillItem*)[[[[itemArray objectAtIndex:0] superview]superview]subviews];
子视图是一个数组。这是你的问题。您可能想将itemView设置为子视图中的项目


也就是说,崩溃可能只是特定于设备,与iOS 7无关。

谢谢您的回复。请告诉我们如何解决这个问题。除了“超级视图”或“子视图”,我应该使用什么?为什么要投否决票?这几乎肯定是问题的原因。