I am making an iPad app compatible for iOS7. App is working perfect in iOS 6 but it crashes in 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;
}
This code is worked perfect in iOS 6 but not in iOS 7.
Here is the crash log :
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
Please if anyone has any idea why it is happening. Please let me know.
Your itemView
, which it looks like you expect to be of type GapsFillItem
, is actually of type NSArray
.
You know this because the crash report is telling you that NSArray
does not recognize the selector named buttonPlaySound
, which I assume is defined on the GapsFillItem
class.
I recommend throwing some NSLog
statements in there to understand how itemView
is becoming an NSArray
.
In general, lines like this are very dubious:
GapsFillItem *itemView = (GapsFillItem*)[[[[itemArray objectAtIndex:0] superview]superview]subviews];
itemView = (GapsFillItem*)[[[itemArray objectAtIndex:0] superview]superview];
One of these two lines is where the problem is. I would recommend avoiding accessing objects via calls to superview upon superview upon subviews etc etc. If you need to reach something via this sort of chain there's most likely a better way.
Best of luck
Edit
At second glance it looks like this will always crash on iPad because of this line:
GapsFillItem *itemView = (GapsFillItem*)[[[[itemArray objectAtIndex:0] superview]superview]subviews];
Subviews is an array. This is your problem. You probably mean to set itemView to an item within subviews.
That said, the crash may just be device specific and have nothing to do with iOS 7.
User contributions licensed under CC BY-SA 3.0