Swift 2: UITableView 'reloadSections' method crash in iOS 9 - ios

My app was working fine prior to the forced upgrade to Swift 2.x. My code below is executed on an IBAction for a button that "collapses" the cell, e.g. it replaces it with another layout and then attempts to reload the cell, which for various reasons I've been forced to include each cell in its own section (so, extensibly I'm reloading the section). I've tried outputting various variables to the terminal; the inputs are sound. I've also tried wrapping this in .beginUpdates() and .endUpdates() and when walking through this in the debugger, it will just throw the below exception on the .endUpdates() call instead of the .reloadSections() call. I have also tried replacing .reloadSections() with a blanket call to .reloadData() and I receive the same stack trace, making me believe it's internal to the TableView object somehow.
// Set Selected Patient Configuration to "Collapsed"
patientList.patients[ sender.tag ].updateConfiguration( collapsedConfiguration )
let animation = UITableViewRowAnimation.Automatic
// Retrieve Current Table View and Animate Changes
let tableView = self.superview!.superview as! UITableView
// Reload Section with Animation
tableView.reloadSections(NSIndexSet( index: sender.tag ), withRowAnimation: animation )
My code will evaluate the backing data's collapsed state and draw it in either the full or collapsed view.
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM insertObject:atIndex:]: index 2 beyond bounds [0 .. 0]'
*** First throw call stack:
(
0 CoreFoundation 0x00e2fa84 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x03235e02 objc_exception_throw + 50
2 CoreFoundation 0x00cdd211 -[__NSArrayM insertObject:atIndex:] + 881
3 Foundation 0x01510134 -[NSKeyValueSlowMutableArray insertObject:atIndex:] + 115
4 CoreFoundation 0x00d38630 -[NSMutableArray insertObjects:count:atIndex:] + 192
5 CoreFoundation 0x00d38322 -[NSMutableArray insertObjectsFromArray:range:atIndex:] + 322
6 CoreFoundation 0x00d381c2 -[NSMutableArray addObjectsFromArray:] + 834
7 UIKit 0x024f4d4f -[UIRuntimeOutletCollectionConnection performConnect] + 964
8 UIKit 0x024f4daf -[UIRuntimeOutletCollectionConnection connect] + 33
9 libobjc.A.dylib 0x0324a00c -[NSObject performSelector:] + 62
10 CoreFoundation 0x00d60571 -[NSArray makeObjectsPerformSelector:] + 273
11 UIKit 0x021b06f6 -[UINib instantiateWithOwner:options:] + 2102
12 UIKit 0x01eeed6c -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 457
13 UIKit 0x01eef173 -[UITableView dequeueReusableCellWithIdentifier:] + 48
14 Halo 0x001b5174 _TFC4Halo18MainViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 2356
15 Halo 0x001be459 _TToFC4Halo18MainViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 89
16 UIKit 0x01f03a19 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 782
17 UIKit 0x01f03b47 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 90
18 UIKit 0x022568cc -[_UITableViewUpdateSupport(Private) _setupAnimationsForNewlyInsertedCells] + 8353
19 UIKit 0x0226181a -[_UITableViewUpdateSupport _setupAnimations] + 161
20 UIKit 0x01ed7fd3 -[UITableView _updateWithItems:updateSupport:] + 3653
21 UIKit 0x01ecfc91 -[UITableView _endCellAnimationsWithContext:] + 17491
22 UIKit 0x01eea538 -[UITableView _updateSections:updateAction:withRowAnimation:headerFooterOnly:] + 460
23 UIKit 0x01eea625 -[UITableView reloadSections:withRowAnimation:] + 73
24 Halo 0x00105e10 _TFC4Halo28FullPatientViewTableViewCell19collapseButtonPressfS0_FCSo8UIButtonT_ + 6208
25 Halo 0x0010645d _TToFC4Halo28FullPatientViewTableViewCell19collapseButtonPressfS0_FCSo8UIButtonT_ + 61
26 libobjc.A.dylib 0x0324a0b5 -[NSObject performSelector:withObject:withObject:] + 84
27 UIKit 0x01d8016a -[UIApplication sendAction:to:from:forEvent:] + 118
28 UIKit 0x01d800e9 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
29 UIKit 0x01f1e19f -[UIControl sendAction:to:forEvent:] + 79
30 UIKit 0x01f1e51f -[UIControl _sendActionsForEvents:withEvent:] + 408
31 UIKit 0x01f1d525 -[UIControl touchesEnded:withEvent:] + 714
32 UIKit 0x022efeaa _UIGestureRecognizerUpdate + 12763
33 UIKit 0x01dfabdf -[UIWindow _sendGesturesForEvent:] + 1559
34 UIKit 0x01dfc298 -[UIWindow sendEvent:] + 1137
35 UIKit 0x01da1efb -[UIApplication sendEvent:] + 266
36 UIKit 0x01d77cb6 _UIApplicationHandleEventQueue + 7802
37 CoreFoundation 0x00d49d1f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
38 CoreFoundation 0x00d3f9ab __CFRunLoopDoSources0 + 523
39 CoreFoundation 0x00d3edc8 __CFRunLoopRun + 1032
40 CoreFoundation 0x00d3e706 CFRunLoopRunSpecific + 470
41 CoreFoundation 0x00d3e51b CFRunLoopRunInMode + 123
42 GraphicsServices 0x058c0664 GSEventRunModal + 192
43 GraphicsServices 0x058c04a1 GSEventRun + 104
44 UIKit 0x01d7e1eb UIApplicationMain + 160
45 Halo 0x0011eb6c main + 140
46 libdyld.dylib 0x03ceca21 start + 1
47 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The stack is not very helpful to me and I can't even figure out the opening message: "insertObject:atIndex:]: index 2 beyond bounds [0 .. 0]." No where in this sample and my test with a single table entry should there be an index of '2.' Any help you could provide would be appreciated.
Here's my 'bt' on this exception:
* thread #1: tid = 0xc9ca7, 0x0401969a libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x0401969a libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x03fe4634 libsystem_pthread.dylib`pthread_kill + 101
frame #2: 0x03d9339d libsystem_c.dylib`abort + 156
frame #3: 0x04034ae7 libc++abi.dylib`abort_message + 151
frame #4: 0x04055683 libc++abi.dylib`default_terminate_handler() + 300
frame #5: 0x032360b6 libobjc.A.dylib`_objc_terminate() + 108
frame #6: 0x04052d0d libc++abi.dylib`std::__terminate(void (*)()) + 14
frame #7: 0x0405293e libc++abi.dylib`__cxa_rethrow + 103
frame #8: 0x03235fad libobjc.A.dylib`objc_exception_rethrow + 47
frame #9: 0x00d3e7d0 CoreFoundation`CFRunLoopRunSpecific + 672
frame #10: 0x00d3e51b CoreFoundation`CFRunLoopRunInMode + 123
frame #11: 0x058c0664 GraphicsServices`GSEventRunModal + 192
frame #12: 0x058c04a1 GraphicsServices`GSEventRun + 104
frame #13: 0x01d7e1eb UIKit`UIApplicationMain + 160
* frame #14: 0x0011eb6c Halo`main + 140 at AppDelegate.swift:26
frame #15: 0x03ceca21 libdyld.dylib`start + 1
Per request, here's the code followed by the output:
// Retrieve Current Table View and Animate Changes
let tableView = self.superview!.superview as! UITableView
// Test Output
print( "tableView.numberOfSections: \(tableView.numberOfSections)" )
print( "tableView.numberOfRowsInSection( sender.tag ): \(tableView.numberOfRowsInSection( sender.tag ))" )
// Reload Section with Animation
tableView.reloadSections(NSIndexSet( index: sender.tag ), withRowAnimation: animation )
tableView.numberOfSections: 1
tableView.numberOfRowsInSection( sender.tag ): 1

This section of the stack trace (probably) means that you have an IBOutletCollection, and UIKit is now trying to populate it from a storyboard or nib:
7 UIKit 0x024f4d4f -[UIRuntimeOutletCollectionConnection performConnect] + 964
8 UIKit 0x024f4daf -[UIRuntimeOutletCollectionConnection connect] + 33
And this section looks like it’s trying to add bound objects to an existing array:
2 CoreFoundation 0x00cdd211 -[__NSArrayM insertObject:atIndex:] + 881
3 Foundation 0x01510134 -[NSKeyValueSlowMutableArray insertObject:atIndex:] + 115
4 CoreFoundation 0x00d38630 -[NSMutableArray insertObjects:count:atIndex:] + 192
5 CoreFoundation 0x00d38322 -[NSMutableArray insertObjectsFromArray:range:atIndex:] + 322
6 CoreFoundation 0x00d381c2 -[NSMutableArray addObjectsFromArray:] + 834
All of that means that the error may not have anything to do with the code you posted, but rather with your nib and how it interacts with the properties it’s bound to.
Take a look at whether you’re using an IBOutletCollection, and if so, start debugging the things it’s bound to.

Related

Unrecognized Selector Instance When Performing Segue

When performing programatically performing a segue, the segue does work and the intended storyboard opens, but terminates immediately afterwards. The view controller/storyboard does work and shouldn't have any errors in the code as I've tested it individually, so I'm not entirely sure as to why it terminates. Any help would be appreciated.
2017-05-01 20:22:59.358605 FInal Project[15659:499662] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/student/Library/Developer/CoreSimulator/Devices/265EA47F-07A6-47C7-A6B4-5E62D37E72BA/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-05-01 20:22:59.376075 FInal Project[15659:499662] [MC] Reading from private effective user settings.
in
2017-05-01 20:23:48.095 FInal Project[15659:499662] <UILayoutContainerView: 0x7fdae3c082f0; frame = (0 0; 414 736); autoresize = W+H; gestureRecognizers = <NSArray: 0x600000242be0>; layer = <CALayer: 0x60000003ea40>>'s window is not equal to <UINavigationController: 0x7fdae40aee00>'s view's window!
2017-05-01 20:23:48.715 FInal Project[15659:499662] -[FInal_Project.User_Info NameInputEditingDidEnd:]: unrecognized selector sent to instance 0x7fdae3c11d40
2017-05-01 20:23:48.721 FInal Project[15659:499662] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FInal_Project.User_Info NameInputEditingDidEnd:]: unrecognized selector sent to instance 0x7fdae3c11d40'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101fc3d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000101a2521e objc_exception_throw + 48
2 CoreFoundation 0x0000000102033f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000101f49005 ___forwarding___ + 1013
4 CoreFoundation 0x0000000101f48b88 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001030cb8bc -[UIApplication sendAction:to:from:forEvent:] + 83
6 UIKit 0x0000000103251c38 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0000000103251f51 -[UIControl _sendActionsForEvents:withEvent:] + 444
8 UIKit 0x0000000103bdbc20 -[UITextField _resignFirstResponder] + 313
9 UIKit 0x00000001032e1778 -[UIResponder _finishResignFirstResponder] + 286
10 UIKit 0x0000000103bdba0e -[UITextField _finishResignFirstResponder] + 49
11 UIKit 0x00000001032e1827 -[UIResponder resignFirstResponder] + 140
12 UIKit 0x0000000103bdb8dd -[UITextField resignFirstResponder] + 136
13 UIKit 0x000000010317802f -[UIView(Hierarchy) _removeFirstResponderFromSubtree] + 167
14 UIKit 0x00000001031786b8 __UIViewWillBeRemovedFromSuperview + 76
15 UIKit 0x000000010317846a -[UIView(Hierarchy) removeFromSuperview] + 95
16 UIKit 0x000000010324d451 __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke.629 + 704
17 UIKit 0x0000000103246fba -[UIPresentationController transitionDidFinish:] + 111
18 UIKit 0x000000010345ef83 -[_UICurrentContextPresentationController transitionDidFinish:] + 42
19 UIKit 0x000000010324aef0 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 183
20 UIKit 0x0000000103c0c56c -[_UIViewControllerTransitionContext completeTransition:] + 102
21 UIKit 0x0000000103243ddc -[UITransitionView notifyDidCompleteTransition:] + 251
22 UIKit 0x0000000103243aef -[UITransitionView _didCompleteTransition:] + 1539
23 UIKit 0x000000010324651c -[UITransitionView _transitionDidStop:finished:] + 104
24 UIKit 0x0000000103156bd5 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 222
25 UIKit 0x000000010315712a -[UIViewAnimationState animationDidStop:finished:] + 136
26 QuartzCore 0x0000000108526648 _ZN2CA5Layer23run_animation_callbacksEPv + 316
27 libdispatch.dylib 0x0000000105e2e0cd _dispatch_client_callout + 8
28 libdispatch.dylib 0x0000000105e0e8a4 _dispatch_main_queue_callback_4CF + 406
29 CoreFoundation 0x0000000101f87e49 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
30 CoreFoundation 0x0000000101f4d37d __CFRunLoopRun + 2205
31 CoreFoundation 0x0000000101f4c884 CFRunLoopRunSpecific + 420
32 GraphicsServices 0x0000000107d38a6f GSEventRunModal + 161
33 UIKit 0x00000001030c9c68 UIApplicationMain + 159
34 FInal Project 0x00000001013fb65f main + 111
35 libdyld.dylib 0x0000000105e7a68d start + 1
36 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The issue (discovered in the comments above) was that there was an action in the storyboard that was no longer hooked up to an action in code.
If anyone else in the future has a similar problem, look through the outlets menu for an outlet or action with the name provided in the console output. In this case, the action was named NameInputEditingDidEnd.
To expand on Nathan's answer, instead of randomly looking around, just cmd+shift+f the name of the outlet, in this case NameInputEditingDidEnd, and xcode will output the storyboard with the dangling outlet for you and center you to it.

Webview.Scrollview - Unable to add more than 126 Objects

My Application is getting crashed while scrolling UIWebview - I have used ILPDFKit for implementing interactive PDF - Editable Forms.App is getting crashed only if i am adding more than 126 Objects.
Here is code I am using (from ILPDFKit)
for (PDFWidgetAnnotationView *element in widgetAnnotationViews)
{
element.alpha = 0;
element.parentView = self;
[_pdfView.scrollView addSubview:element];
[_pdfView.scrollView bringSubviewToFront:element];
if ([element isKindOfClass:[PDFFormButtonField class]])
{
[(PDFFormButtonField*)element setButtonSuperview];
}
}
I have also raise Issue here
I have added some customview's in my webview.scrollview , so while scrolling webview my App is getting crashed. i have checked for all possible solutions i found on google/stackoverflow.
none of the delegate method of scrollview / webview called before this crash , as soon as i tried to scroll and app is getting crashed.
below is crash report.
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x6000024535f0> was mutated while being enumerated.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001045dd34b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000103f5f21e objc_exception_throw + 48
2 CoreFoundation 0x0000000104645f1c __NSFastEnumerationMutationHandler + 124
3 CoreFoundation 0x0000000104582638 -[NSArray makeObjectsPerformSelector:] + 424
4 UIKit 0x00000001020d8f4f -[UIScrollView(UIScrollViewInternal) _notifyDidScroll] + 163
5 UIKit 0x00000001020c3919 -[UIScrollView setContentOffset:] + 478
6 UIKit 0x00000001020c8351 -[UIScrollView _updatePanGesture] + 2346
7 UIKit 0x0000000102531289 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 57
8 UIKit 0x0000000102539028 _UIGestureRecognizerSendTargetActions + 109
9 UIKit 0x0000000102536af7 _UIGestureRecognizerSendActions + 227
10 UIKit 0x0000000102535d83 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 891
11 UIKit 0x0000000102521e56 _UIGestureEnvironmentUpdate + 1395
12 UIKit 0x000000010252189b -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 521
13 UIKit 0x0000000102520a7e -[UIGestureEnvironment _updateGesturesForEvent:window:] + 286
14 UIKit 0x000000010205f7ad -[UIWindow sendEvent:] + 3989
15 UIKit 0x000000010200ca33 -[UIApplication sendEvent:] + 371
16 UIKit 0x00000001027feb6d __dispatchPreprocessedEventFromEventQueue + 3248
17 UIKit 0x00000001027f7817 __handleEventQueue + 4879
18 CoreFoundation 0x0000000104582311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19 CoreFoundation 0x000000010456759c __CFRunLoopDoSources0 + 556
20 CoreFoundation 0x0000000104566a86 __CFRunLoopRun + 918
21 CoreFoundation 0x0000000104566494 CFRunLoopRunSpecific + 420
22 GraphicsServices 0x0000000107910a6f GSEventRunModal + 161
23 UIKit 0x0000000101feef34 UIApplicationMain + 159
24 HyundaiCapital 0x000000010132a67f main + 111
25 libdyld.dylib 0x000000010610268d start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Edit
1.How many subviews at most i can add into delegate of scrollview at a time?
2.I am only getting this crash if i am adding subviews more than 126?
Solution
Updating ILPDFKit worked for me.

11DB Terminating app due to uncaught exception 'NSInternalInconsistencyException'

I a rookie in OBjective C. I am writing a login feature in Xcode. But it crashes. Seeking for help!
2016-02-06 03:14:09.331 Login[3466:392205] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'ViewController''
* First throw call stack:
(
0 CoreFoundation 0x0000000101b81f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001015fbdeb objc_exception_throw + 48
2 CoreFoundation 0x0000000101b81e7d +[NSException raise:format:] + 205
3 UIKit 0x00000001022e4eff -[UINib instantiateWithOwner:options:] + 499
4 UIKit 0x00000001020bfc16 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
5 UIKit 0x00000001020c0542 -[UIViewController loadView] + 178
6 UIKit 0x00000001020c08a0 -[UIViewController loadViewIfRequired] + 138
7 UIKit 0x00000001020c1013 -[UIViewController view] + 27
8 UIKit 0x0000000101f9a51c -[UIWindow addRootViewControllerViewIfPossible] + 61
9 UIKit 0x0000000101f9ac05 -[UIWindow _setHidden:forced:] + 282
10 UIKit 0x0000000101fac4a5 -[UIWindow makeKeyAndVisible] + 42
11 UIKit 0x0000000101f26396 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
12 UIKit 0x0000000101f2c9c3 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1750
13 UIKit 0x0000000101f29ba3 -[UIApplication workspaceDidEndTransaction:] + 188
14 FrontBoardServices 0x00000001048d9784 -[FBSSerialQueue _performNext] + 192
15 FrontBoardServices 0x00000001048d9af2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
16 CoreFoundation 0x0000000101aae011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17 CoreFoundation 0x0000000101aa3f3c __CFRunLoopDoSources0 + 556
18 CoreFoundation 0x0000000101aa33f3 __CFRunLoopRun + 867
19 CoreFoundation 0x0000000101aa2e08 CFRunLoopRunSpecific + 488
20 UIKit 0x0000000101f294f5 -[UIApplication _run] + 402
21 UIKit 0x0000000101f2e30d UIApplicationMain + 171
22 Login 0x00000001010fd33f main + 111
23 libdyld.dylib 0x00000001042a592d start + 1
24 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) bt
* thread #1: tid = 0x5fc0d, 0x00000001045db286 libsystem_kernel.dylib__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00000001045db286 libsystem_kernel.dylib__pthread_kill + 10
frame #1: 0x00000001045a49f9 libsystem_pthread.dylibpthread_kill + 90
frame #2: 0x000000010434ca44 libsystem_c.dylibabort + 129
frame #3: 0x000000010414a051 libc++abi.dylibabort_message + 257
frame #4: 0x000000010416fac9 libc++abi.dylibdefault_terminate_handler() + 267
frame #5: 0x00000001015fc046 libobjc.A.dylib_objc_terminate() + 103
frame #6: 0x000000010416d26e libc++abi.dylibstd::__terminate(void (*)()) + 8
frame #7: 0x000000010416cef9 libc++abi.dylib__cxa_rethrow + 99
frame #8: 0x00000001015fbf5e libobjc.A.dylibobjc_exception_rethrow + 40
frame #9: 0x0000000101aa2ec4 CoreFoundationCFRunLoopRunSpecific + 676
frame #10: 0x0000000101f294f5 UIKit-[UIApplication _run] + 402
frame #11: 0x0000000101f2e30d UIKitUIApplicationMain + 171
* frame #12: 0x00000001010fd33f Loginmain(argc=1, argv=0x00007fff5eb02650) + 111 at main.m:14
frame #13: 0x00000001042a592d libdyld.dylib`start + 1
(lldb)
To fix the problem,in Two ways:
Option-1
regarding the nib name. Check the nib name spelling, it's correct, case sensitive.
Option-2
if option -1 does not work try this
Open XCode Target
Go to the "Build phases" tab
Click the "Copy bundle resources" section
Click the add button
Add the missing Nib file
then works fine

copywithzone exception on object not included in current class

I am using a 4 UIButton that bring up the same UIPickerView but with different NSArray(4) appearing for each button. Using a 4 bool to let the UIPickerView to decide which to load, and which row's text to grab. The buttons methods just include the four bool properties, that sets the three to false and the correct one(button tapped) to true. Then UIViewAnimateWithDuration is called that brings up the UIPickerView (printed in a UIView - for both UIPickerView and UIToolbar to work together). All buttons are working just fine(no matter how many time I bring/close the UIPickerView)apart from one (even if it is pressed in first-middle-last-any order). Xcode throws the following exception:
What I did:
remove the button, create a new one
tried both storyboard/controller method of creating a button
added method to button using addtarget
linked button with method using storyboard
So what I am asking if anyone can see anything that I cannot see in my debugger's exception thrown:(sportCenter is a NSObject and it is not imported in this controller -tried that too!)
2015-11-05 13:14:36.356 -----[3975:1397857] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[sportCenter copyWithZone:]: unrecognized selector sent to instance 0x7f8709f62250'
*** First throw call stack:
(
0 CoreFoundation 0x0000000103673f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001030eddeb objc_exception_throw + 48
2 CoreFoundation 0x000000010367c56d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001035c9eea ___forwarding___ + 970
4 CoreFoundation 0x00000001035c9a98 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000103c8954b -[UILabel _setText:] + 114
6 UIKit 0x0000000103a0580c -[UIPickerView tableView:cellForRowAtIndexPath:] + 863
7 UIKit 0x000000010429c146 -[UIPickerColumnView tableView:cellForRowAtIndexPath:] + 103
8 UIKit 0x0000000103b75e2a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 782
9 UIKit 0x0000000103b75f3f -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
10 UIKit 0x0000000103b4b307 -[UITableView _updateVisibleCellsNow:isRecursive:] + 3187
11 UIKit 0x0000000103b5d369 -[UITableView cellForRowAtIndexPath:] + 186
12 UIKit 0x000000010412419a -[UIPickerTableView selectRow:animated:notify:] + 342
13 UIKit 0x0000000103a0421f -[UIPickerView _resetSelectionOfTables] + 157
14 UIKit 0x0000000103a040ab __30-[UIPickerView layoutSubviews]_block_invoke + 9523
15 UIKit 0x0000000103ac9c10 +[UIView(Animation) performWithoutAnimation:] + 65
16 UIKit 0x0000000103a01b33 -[UIPickerView layoutSubviews] + 147
17 UIKit 0x0000000103a04fcb -[UIPickerView selectedRowInComponent:] + 45
18 UIKit 0x0000000103a0009e -[UIPickerView _updateSelectedRows] + 135
19 UIKit 0x0000000103a001cf -[UIPickerView didMoveToWindow] + 117
20 UIKit 0x0000000103acebe0 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1768
21 UIKit 0x0000000103ace856 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 862
22 UIKit 0x0000000103ac3e2c __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 155
23 Foundation 0x0000000102cc3d4a -[NSISEngine withBehaviors:performModifications:] + 155
24 UIKit 0x0000000103ac3d4a -[UIView(Hierarchy) _postMovedFromSuperview:] + 575
25 UIKit 0x0000000103ad17e7 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1967
26 --- 0x00000001026cbe7b -[AllOngoingViewController animatePickerView] + 107
27 --- 0x00000001026cbcd7 -[AllOngoingViewController centersAreTapped] + 71
28 UIKit 0x0000000103f0194f _UIGestureRecognizerSendTargetActions + 153
29 UIKit 0x0000000103efdfc1 _UIGestureRecognizerSendActions + 162
30 UIKit 0x0000000103efbfbe -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 843
31 UIKit 0x0000000103f04283 ___UIGestureRecognizerUpdate_block_invoke898 + 79
32 UIKit 0x0000000103f04121 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 342
33 UIKit 0x0000000103ef1bdd _UIGestureRecognizerUpdate + 2634
34 UIKit 0x0000000103a8f9c0 -[UIWindow _sendGesturesForEvent:] + 1137
35 UIKit 0x0000000103a90bf6 -[UIWindow sendEvent:] + 849
36 UIKit 0x0000000103a402fa -[UIApplication sendEvent:] + 263
37 UIKit 0x0000000103a1aabf _UIApplicationHandleEventQueue + 6844
38 CoreFoundation 0x00000001035a0011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
39 CoreFoundation 0x0000000103595f3c __CFRunLoopDoSources0 + 556
40 CoreFoundation 0x00000001035953f3 __CFRunLoopRun + 867
41 CoreFoundation 0x0000000103594e08 CFRunLoopRunSpecific + 488
42 GraphicsServices 0x0000000106616ad2 GSEventRunModal + 161
43 UIKit 0x0000000103a2030d UIApplicationMain + 171
44 ----- 0x00000001026c1caf main + 111
45 libdyld.dylib 0x000000010a19e92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
You must add your own copyWithZone: method in your objects...
However, I don't really understand your question / context. It looks designed in a bit complex way. Booleans array have chances to be a bad approach. It is better to have a selectedButton ( UIButton ) property in your controller, to know which one is selected, than maintain four booleans.
And finally, no matter the situation, if things are working for all objects, excepted the first one, it often means that you have an array index error somewhere.
I hope it helps.

how to deal with Terminating app due to uncaught exception

Not getting why the app is crashing random time. unable to find any str. Please help.. I am not able to track the issue by this log. please also help me how to deal with such difficult log to track where exactly the issue is.
Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSSetM: 0x7fda3c871090> was mutated while being enumerated.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000105ed1f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000104ce1bb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000105ed1894 __NSFastEnumerationMutationHandler + 132
3 Foundation 0x000000010488e3be -[NSISEngine _coreReplaceMarker:withMarkerPlusDelta:] + 347
4 Foundation 0x000000010488e1dc -[NSISEngine constraintDidChangeSuchThatMarker:shouldBeReplacedByMarkerPlusDelta:] + 239
5 Foundation 0x000000010488adea -[NSLayoutConstraint _containerGeometryDidChange] + 310
6 UIKit 0x0000000103c03a04 ___UITagLayoutConstraintsForConstantChangeForSelectedAttributes_block_invoke + 409
7 UIKit 0x0000000103c1027b -[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] + 115
8 UIKit 0x0000000103c03865 _UITagLayoutConstraintsForConstantChangeForSelectedAttributes + 80
9 UIKit 0x00000001035ea079 -[UIView _layoutMarginsDidChange] + 60
10 UIKit 0x00000001035ea248 -[UIView setLayoutMargins:] + 426
11 UIKit 0x00000001036a9296 -[UIViewController _setContentOverlayInsets:] + 270
12 UIKit 0x00000001036a9bc7 -[UIViewController _updateContentOverlayInsetsFromParentIfNecessary] + 1857
13 UIKit 0x00000001036038cd -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
14 QuartzCore 0x0000000109d9dde8 -[CALayer layoutSublayers] + 150
15 QuartzCore 0x0000000109d92a0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
16 QuartzCore 0x0000000109d9287e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
17 QuartzCore 0x0000000109d0063e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
18 QuartzCore 0x0000000109d0174a _ZN2CA11Transaction6commitEv + 390
19 UIKit 0x000000010358714d _UIApplicationHandleEventQueue + 2035
20 CoreFoundation 0x0000000105e07551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x0000000105dfd41d __CFRunLoopDoSources0 + 269
22 CoreFoundation 0x0000000105dfca54 __CFRunLoopRun + 868
23 CoreFoundation 0x0000000105dfc486 CFRunLoopRunSpecific + 470
24 GraphicsServices 0x0000000107a659f0 GSEventRunModal + 161
25 UIKit 0x000000010358a420 UIApplicationMain + 1282
26 HomeDiary 0x0000000102c861c3 main + 115
27 libdyld.dylib 0x0000000106fa5145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) bt
* thread #1: tid = 0x1f5db, 0x00000001072c3286 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00000001072c3286 libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x00000001072f642f libsystem_pthread.dylib`pthread_kill + 90
frame #2: 0x000000010705319a libsystem_sim_c.dylib`abort + 129
frame #3: 0x0000000106e14481 libc++abi.dylib`abort_message + 257
frame #4: 0x0000000106e3c3d5 libc++abi.dylib`default_terminate_handler() + 267
frame #5: 0x0000000104ce1e19 libobjc.A.dylib`_objc_terminate() + 103
frame #6: 0x0000000106e39b01 libc++abi.dylib`std::__terminate(void (*)()) + 8
frame #7: 0x0000000106e397aa libc++abi.dylib`__cxa_rethrow + 99
frame #8: 0x0000000104ce1d2c libobjc.A.dylib`objc_exception_rethrow + 40
frame #9: 0x0000000105dfc53e CoreFoundation`CFRunLoopRunSpecific + 654
frame #10: 0x0000000107a659f0 GraphicsServices`GSEventRunModal + 161
frame #11: 0x000000010358a420 UIKit`UIApplicationMain + 1282
* frame #12: 0x0000000102c861c3 HomeDiary`main(argc=1, argv=0x00007fff5cf8e348) + 115 at main.m:16
frame #13: 0x0000000106fa5145 libdyld.dylib`start + 1
The reason it is crashing is in the first line... Collection <__NSSetM: 0x7fda3c871090> was mutated while being enumerated.
This means you have an NSMutableSet and you are enumerating it for (id someObject in mySet) {} or [mySet enumerateObjects... and inside that enumeration you are mutating the set.
Something like this...
for (id someObject in mySet) {
[mySet removeObject:someObject];
}
Or something like that. You can't do this, it will crash... hence your crash.
To find where this is happening you need to add an Exception Breakpoint to the project. This will then stop the execution on the line of code causing the crash.

Resources