我正在制作兼容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
如果有人知道为什么会这样。请告诉我。
答案 0 :(得分:3)
您的itemView
看起来像是GapsFillItem
类型,实际上是NSArray
类型。
您知道这一点,因为崩溃报告告诉您NSArray
无法识别名为buttonPlaySound
的选择器,我认为该选择器是在GapsFillItem
类上定义的。
我建议在其中添加一些NSLog
语句,以了解itemView
如何成为NSArray
。
一般来说,这样的行非常可疑:
GapsFillItem *itemView = (GapsFillItem*)[[[[itemArray objectAtIndex:0] superview]superview]subviews];
itemView = (GapsFillItem*)[[[itemArray objectAtIndex:0] superview]superview];
这两行中的一行是问题所在。我建议通过超级浏览调查超级视图以避免访问对象等等。如果你需要通过这种链接到某些东西,那么最有可能是更好的方式。
祝你好运
修改
乍一看,由于这条线路,它看起来总会在iPad上崩溃:
GapsFillItem *itemView = (GapsFillItem*)[[[[itemArray objectAtIndex:0] superview]superview]subviews];
子视图是一个数组。这是你的问题。您可能需要将itemView设置为子视图中的项目。
也就是说,崩溃可能只是设备特定的,与iOS 7无关。