简体   繁体   中英

Changing orientation error IOS

I am having an exception while trying to change orientation. I can't seem to get through this exception. the exception itself does not help because it keeps on pointing to the line of code that allows me to change orientation but the description says attempt to insert nil from objects[0] which indicates error in inserting to an array. I tried exception breakpoint and instruments in debugging. also had nszombie turned on. also made sure to check if nil before adding to an array or initializing an array. so i dont know anymore what could be the problem or what sort of action i would do to fix this. as for the array i have an array named arraydata that is initialized at viewdidload. when it is nil and/or count < 1. i call upon a af response that populates the array so it is made sure that it has content. also the logs are fine it returns count > 0 always. anyways I hope someone can help here is the exception. Thanks in advance

2015-10-02 21:40:18.801 NCR Video[4755:94868] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
0   CoreFoundation                      0x00000001126bdc65 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x0000000112356bb7 objc_exception_throw + 45
2   CoreFoundation                      0x0000000112582478 -[__NSPlaceholderArray initWithObjects:count:] + 360
3   CoreFoundation                      0x00000001125e1384 +[NSArray arrayWithObjects:count:] + 52
4   UIKit                               0x000000010ff6b83f _UIViewTopDownSubtreeTraversal + 127
5   UIKit                               0x000000011004aa57 -[UIViewController _replaceViewControllerInPresentationHierarchy:] + 120
6   UIKit                               0x000000011004a9a5 -[UIViewController _adaptedPresentationControllerForTraitCollection:withTransitionCoordinator:] + 430
7   UIKit                               0x000000011001f823 -[UIPresentationController _sharedParent:willTransitionToTraitCollection:withTransitionCoordinator:] + 273
8   UIKit                               0x000000011001f6f2 -[UIPresentationController _window:willTransitionToTraitCollection:withTransitionCoordinator:] + 37
9   UIKit                               0x000000011003dcaa -[UIViewController _window:willTransitionToTraitCollection:withTransitionCoordinator:] + 337
10  UIKit                               0x000000011003dcaa -[UIViewController _window:willTransitionToTraitCollection:withTransitionCoordinator:] + 337
11  UIKit                               0x000000011003dcaa -[UIViewController _window:willTransitionToTraitCollection:withTransitionCoordinator:] + 337
12  UIKit                               0x000000010ff5f891 -[UIWindow _rotateToBounds:withAnimator:transitionContext:] + 321
13  UIKit                               0x000000010ff61cb7 -[UIWindow _rotateWindowToOrientation:updateStatusBar:duration:skipCallbacks:] + 1741
14  UIKit                               0x000000010ff625fa -[UIWindow _setRotatableClient:toOrientation:applyTransformToWindow:updateStatusBar:duration:force:isRotating:] + 559
15  UIKit                               0x000000010ff6156e -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 116
16  UIKit                               0x000000010ff614f4 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 36
17  UIKit                               0x000000010ff613a1 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 122
18  UIKit                               0x000000010ff6043e __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 98
19  UIKit                               0x000000010ff6038e -[UIWindow _updateToInterfaceOrientation:duration:force:] + 391
20  UIKit                               0x000000010ff607d0 -[UIWindow _updateInterfaceOrientationFromDeviceOrientation:] + 316
21  CoreFoundation                      0x000000011268d54c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
22  CoreFoundation                      0x000000011258ba04 _CFXNotificationPost + 2484
23  Foundation                          0x000000010fa4e968 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
24  UIKit                               0x0000000110187e59 -[UIDevice setOrientation:animated:] + 282
25  Foundation                          0x000000010fa8db53 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
26  NCR Video                           0x000000010e44ea0b -[PlayRealStream toFullScreen] + 779
27  NCR Video                           0x000000010e454611 -[PlayRealStream fullscr:] + 177
28  UIKit                               0x000000010ff0fda2 -[UIApplication sendAction:to:from:forEvent:] + 75
29  UIKit                               0x000000011002154a -[UIControl _sendActionsForEvents:withEvent:] + 467
30  UIKit                               0x0000000110020919 -[UIControl touchesEnded:withEvent:] + 522
31  UIKit                               0x000000010ff5c998 -[UIWindow _sendTouchesForEvent:] + 735
32  UIKit                               0x000000010ff5d2c2 -[UIWindow sendEvent:] + 682
33  UIKit                               0x000000010ff23581 -[UIApplication sendEvent:] + 246
34  UIKit                               0x000000010ff30d1c _UIApplicationHandleEventFromQueueEvent + 18265
35  UIKit                               0x000000010ff0b5dc _UIApplicationHandleEventQueue + 2066
36  CoreFoundation                      0x00000001125f1431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
37  CoreFoundation                      0x00000001125e72fd __CFRunLoopDoSources0 + 269
38  CoreFoundation                      0x00000001125e6934 __CFRunLoopRun + 868
39  CoreFoundation                      0x00000001125e6366 CFRunLoopRunSpecific + 470
40  GraphicsServices                    0x0000000114fd1a3e GSEventRunModal + 161
41  UIKit                               0x000000010ff0e900 UIApplicationMain + 1282
42  NCR Video                           0x000000010e42549f main + 111
43  libdyld.dylib                       0x00000001138bb145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

(lldb) 

Initializing the array at viewDidLoad

self.arrayData = [[NSMutableArray alloc]init];

at an initializing method

if(StreamList!=nil && StreamList.count > 0)
self.arrayData = [NSMutableArray arraywithArray:StreamList];

where StreamList is an nsarray containing objects

OK I have figured out a solution for you. Just implement this method exactly like it is:

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM