ICViewPager icon indicating copy to clipboard operation
ICViewPager copied to clipboard

App Crashing if we make array with no contents

Open fparkar opened this issue 11 years ago • 1 comments

I am trying to using your control and it works smoothly.

I just face one issue. Before I call my feeds data, ViewPagerController delegate are getting called. At that time I have feeds as null.

Crash I get is at below line in ViewPagerController

[self.pageViewController setViewControllers:@[viewController] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

In Log, I see below details.

2013-11-20 15:54:52.476 Garage[1517:a0b] * 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 0x01fa05e4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x019f48b6 objc_exception_throw + 44 2 CoreFoundation 0x01f54386 -[__NSPlaceholderArray initWithObjects:count:] + 390 3 CoreFoundation 0x01f66dc2 +[NSArray arrayWithObjects:count:] + 66 4 Garage 0x000a38ac -[ViewPagerController setActiveContentIndex:] + 316 5 Garage 0x000a5b5e -[ViewPagerController selectTabAtIndex:] + 94 6 Garage 0x000a9624 -[ViewPagerController defaultSetup] + 8660 7 Garage 0x000a0939 -[ViewPagerController viewWillAppear:] + 137 8 Garage 0x00055682 -[DirectoryViewController viewWillAppear:] + 98 9 UIKit 0x0087e28a -[UIViewController _setViewAppearState:isAnimating:] + 419 10 UIKit 0x0087e695 __52-[UIViewController _setViewAppearState:isAnimating:]_block_invoke + 325 11 CoreFoundation 0x0201d05d __53-[__NSArrayI enumerateObjectsWithOptions:usingBlock:]_block_invoke + 61 12 CoreFoundation 0x0201cf92 -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 258 13 CoreFoundation 0x01f9a0a5 -[NSArray enumerateObjectsUsingBlock:] + 53 14 UIKit 0x0087e444 -[UIViewController _setViewAppearState:isAnimating:] + 861 15 UIKit 0x0087e798 -[UIViewController __viewWillAppear:] + 114 16 UIKit 0x0088f310 -[UIViewController(UIContainerViewControllerProtectedMethods) beginAppearanceTransition:animated:] + 199 17 UIKit 0x00894b8e -[UINavigationController _startCustomTransition:] + 1062 18 UIKit 0x008a1757 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688 19 UIKit 0x008a2349 -[UINavigationController __viewWillLayoutSubviews] + 57 20 UIKit 0x009db39d -[UILayoutContainerView layoutSubviews] + 213 21 UIKit 0x007d1dd7 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355 22 libobjc.A.dylib 0x01a0681f -[NSObject performSelector:withObject:] + 70 23 QuartzCore 0x0043472a -[CALayer layoutSublayers] + 148 24 QuartzCore 0x00428514 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 25 QuartzCore 0x00428380 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26 26 QuartzCore 0x00390156 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294 27 QuartzCore 0x003914e1 _ZN2CA11Transaction6commitEv + 393 28 QuartzCore 0x00391bb4 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92 29 CoreFoundation 0x01f6853e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30 30 CoreFoundation 0x01f6848f __CFRunLoopDoObservers + 399 31 CoreFoundation 0x01f463b4 __CFRunLoopRun + 1076 32 CoreFoundation 0x01f45b33 CFRunLoopRunSpecific + 467 33 CoreFoundation 0x01f4594b CFRunLoopRunInMode + 123 34 GraphicsServices 0x02f399d7 GSEventRunModal + 192 35 GraphicsServices 0x02f397fe GSEventRun + 104 36 UIKit 0x0076794b UIApplicationMain + 1225 37 Garage 0x00026e32 main + 130 38 libdyld.dylib 0x06559725 start + 0 ) libc++abi.dylib: terminating with uncaught exception of type NSException

To test in your app, you can make below change

pragma mark - ViewPagerDataSource

  • (NSUInteger)numberOfTabsForViewPager:(ViewPagerController *)viewPager { return 0; }

return 0; is the change.

Also as an future, you can add also below point (as per our email conversation).

If some tab is selected, text of that tab get's changed.

fparkar avatar Nov 20 '13 12:11 fparkar

@fparkar a bit late but you can simply fix this issue by inserting

self.view.userInteractionEnabled = self.tabCount > 0;

under

self.tabCount = [self.dataSource numberOfTabsForViewPager:self]; in defaultSetup

pplant avatar Apr 28 '16 09:04 pplant