NSUndoManager errors with "unrecognized selector sent to instance" - ios

Working on implementing NSUndoManager within an iOS9 app. Current undo code looks like this:
func setActiveColorData(colorData: ColorData) {
if colorData != activeColorData {
print(self)
undoManager?.registerUndoWithTarget(self, selector: "setActiveColorData:", object: activeColorData!)
undoManager?.setActionName("Change color")
print("Set undo action")
activeColorData = colorData
}
}
ColorData is just a simple class with three floats inside of it (hue, saturation, brightness) and some utility methods.
Everything works fine, including the shake gesture which brings up the undo prompt. But once you click undo, the app crashes and the following error:
2016-02-25 16:26:58.225 Color[89399:5503615] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Color.PickerViewController setActiveColorData:]: unrecognized selector sent to instance 0x7fa080776820'
*** First throw call stack:
(
0 CoreFoundation 0x0000000105b75e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000108159deb objc_exception_throw + 48
2 CoreFoundation 0x0000000105b7e48d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000105acb90a ___forwarding___ + 970
4 CoreFoundation 0x0000000105acb4b8 _CF_forwarding_prep_0 + 120
5 Foundation 0x00000001066b2feb -[_NSUndoStack popAndInvoke] + 261
6 Foundation 0x00000001066b2162 -[NSUndoManager undoNestedGroup] + 424
7 UIKit 0x0000000106c46813 -[UIApplication alertView:clickedButtonAtIndex:] + 151
8 UIKit 0x0000000106f63589 -[UIAlertView _prepareToDismissForTappedIndex:] + 136
9 UIKit 0x0000000106f62fc7 __35-[UIAlertView _prepareAlertActions]_block_invoke50 + 53
10 UIKit 0x0000000106f54572 -[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:] + 133
11 UIKit 0x0000000107604eb6 -[_UIAlertControllerView _handleActionSelectionGestureRecognizer:] + 694
12 UIKit 0x000000010711ee73 _UIGestureRecognizerSendTargetActions + 153
13 UIKit 0x000000010711b4e5 _UIGestureRecognizerSendActions + 162
14 UIKit 0x00000001071194e2 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 843
15 UIKit 0x00000001071219a0 ___UIGestureRecognizerUpdate_block_invoke904 + 79
16 UIKit 0x000000010712183e _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 342
17 UIKit 0x000000010710f101 _UIGestureRecognizerUpdate + 2634
18 UIKit 0x0000000106ca6f8a -[UIWindow _sendGesturesForEvent:] + 1137
19 UIKit 0x0000000106ca81c0 -[UIWindow sendEvent:] + 849
20 UIKit 0x0000000106c56b66 -[UIApplication sendEvent:] + 263
21 UIKit 0x0000000106c30d97 _UIApplicationHandleEventQueue + 6844
22 CoreFoundation 0x0000000105aa1a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
23 CoreFoundation 0x0000000105a9795c __CFRunLoopDoSources0 + 556
24 CoreFoundation 0x0000000105a96e13 __CFRunLoopRun + 867
25 CoreFoundation 0x0000000105a96828 CFRunLoopRunSpecific + 488
26 GraphicsServices 0x000000010a416ad2 GSEventRunModal + 161
27 UIKit 0x0000000106c36610 UIApplicationMain + 171
28 Color 0x00000001052a2a7d main + 109
29 libdyld.dylib 0x0000000108c9992d start + 1
30 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I've check the PickerViewController instance and the memory locations match up (from the print(self) line, in this case 0x7fa080776820). Any idea why it can't invoke this selector? Or is it something else? Thanks!

I'm seeing this same kind of crash in a photo editing app when memory is running low. When I get a memory warning, I clear the undo manager but in my case I believe this crash happens because the memory is getting deleted out from under the undo manager.
In case it's related: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/UndoArchitecture/Articles/CleaningUndoStack.html

Related

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.

Extension UIScrollView in one target. Use extended methods in UITableView instance will crash in another target

In Cocoa Touch Framework Target. I add following methods to UIScrollView.
public extension UIScrollView {
public func beginRefresh() {
print("beginRefresh")
}
public func endRefresh() {
print("endRefresh")
}
}
In iOS App Target as Demo App. I invoke those methods on UITableView instance. It crash.
override func viewDidLoad() {
super.viewDidLoad()
tableView.beginRefresh()
}
Crash Log:
2016-08-10 16:22:29.736 DTRefresh iOS Example[7373:210619]
-[UITableView beginRefresh]: unrecognized selector sent to instance 0x7fc91b019e00 2016-08-10 16:22:29.751 DTRefresh iOS
Example[7373:210619] * Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[UITableView beginRefresh]:
unrecognized selector sent to instance 0x7fc91b019e00'
* First throw call stack: ( 0 CoreFoundation 0x0000000109c39d85 exceptionPreprocess + 165 1 libobjc.A.dylib
0x000000010b9dddeb objc_exception_throw + 48 2 CoreFoundation
0x0000000109c42d3d -[NSObject(NSObject) doesNotRecognizeSelector:] +
205 3 CoreFoundation 0x0000000109b88cfa
___forwarding_ + 970 4 CoreFoundation 0x0000000109b888a8 _CF_forwarding_prep_0 + 120 5 DTRefresh iOS
Example 0x0000000109a54a81
_TFC21DTRefresh_iOS_Example18ListViewController11viewDidLoadfT_T_ + 561 6 DTRefresh iOS Example 0x0000000109a54b22
_TToFC21DTRefresh_iOS_Example18ListViewController11viewDidLoadfT_T_ + 34 7 UIKit 0x000000010a5fc984
-[UIViewController loadViewIfRequired] + 1198 8 UIKit 0x000000010a5fccd3 -[UIViewController view] + 27 9 UIKit
0x000000010a4d2fb4 -[UIWindow addRootViewControllerViewIfPossible] +
61 10 UIKit 0x000000010a4d369d
-[UIWindow _setHidden:forced:] + 282 11 UIKit 0x00000001193a5d16 -[UIWindowAccessibility
_orderFrontWithoutMakingKey] + 68 12 UIKit 0x000000010a4e5180 -[UIWindow makeKeyAndVisible] + 42 13 UIKit
0x000000010a459ed9 -[UIApplication
_callInitializationDelegatesForMainScene:transitionContext:] + 4131 14 UIKit 0x000000010a460568
-[UIApplication _runWithMainScene:transitionContext:completion:] + 1769 15 UIKit 0x000000010a45d714
-[UIApplication workspaceDidEndTransaction:] + 188 16 FrontBoardServices 0x000000010d86e8c8
FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24 17 FrontBoardServices 0x000000010d86e741
-[FBSSerialQueue _performNext] + 178 18 FrontBoardServices 0x000000010d86eaca -[FBSSerialQueue _performNextFromRunLoopSource] +
45 19 CoreFoundation 0x0000000109b5f301
CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 20 CoreFoundation 0x0000000109b5522c
__CFRunLoopDoSources0 + 556 21 CoreFoundation 0x0000000109b546e3 __CFRunLoopRun + 867 22 CoreFoundation
0x0000000109b540f8 CFRunLoopRunSpecific + 488 23 UIKit
0x000000010a45cf21 -[UIApplication _run] + 402 24 UIKit
0x000000010a461f09 UIApplicationMain + 171 25 DTRefresh iOS Example
0x0000000109a54662 main + 114 26 libdyld.dylib
0x000000010c4a192d start + 1 27 ???
0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with
uncaught exception of type NSException

"Show" Segue made from dragging button to view controller throws error

Here's what I did: I control dragged from the button to the viewController and starting the app is fine. However, when I click the "let's get started" button, which should segue into the next part of the app, I just get an error. What am I doing wrong?
Latest version of xcode (not beta) and code I wrote (I didn't write any code for the segue though) was in swift.
Also, the error message I'm getting
Registration for remote notification failed with error: REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION
2016-07-28 14:20:53.108 TouchLogin[6368:503476] -[TouchLogin.BWWalkthroughPageViewController GetStarted:]: unrecognized selector sent to instance 0x7f8cc351b360
2016-07-28 14:20:53.111 TouchLogin[6368:503476] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TouchLogin.BWWalkthroughPageViewController GetStarted:]: unrecognized selector sent to instance 0x7f8cc351b360'
*** First throw call stack:
(
0 CoreFoundation 0x000000010132bd85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000103310deb objc_exception_throw + 48
2 CoreFoundation 0x0000000101334d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010127acfa ___forwarding___ + 970
4 CoreFoundation 0x000000010127a8a8 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000101d96a8d -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x0000000101f09e67 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0000000101f0a143 -[UIControl _sendActionsForEvents:withEvent:] + 327
8 UIKit 0x0000000101f09263 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x000000010227ec52 _UIGestureRecognizerUpdate + 10279
10 UIKit 0x0000000101e0948e -[UIWindow _sendGesturesForEvent:] + 1137
11 UIKit 0x0000000101e0a6c4 -[UIWindow sendEvent:] + 849
12 UIKit 0x0000000101db5dc6 -[UIApplication sendEvent:] + 263
13 UIKit 0x0000000101d8f553 _UIApplicationHandleEventQueue + 6660
14 CoreFoundation 0x0000000101251301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x000000010124722c __CFRunLoopDoSources0 + 556
16 CoreFoundation 0x00000001012466e3 __CFRunLoopRun + 867
17 CoreFoundation 0x00000001012460f8 CFRunLoopRunSpecific + 488
18 GraphicsServices 0x000000010496dad2 GSEventRunModal + 161
19 UIKit 0x0000000101d94f09 UIApplicationMain + 171
20 TouchLogin 0x0000000100fa6cc2 main + 114
21 libdyld.dylib 0x000000010437192d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

segmented control - unrecognized selector sent to instance

I want to use sender to get the value from segmented control, but I am getting the unrecognized selector sent to instance error. The segmented control was added within a view. I've tried removing the semicolon and/or sender and none of the prior posts I've found seem to help. Any ideas?
Swift Code
var segCntrl = UISegmentedControl(items: ["Yes","No"])
segCntrl.tag = 100
segCntrl.center = CGPointMake(qView.bounds.width/2, qView.bounds.minY+40)
self.qView.addSubview(segCntrl)
func segmentorSwitch(sender: AnyObject) {
if(sender.selectedSegmentIndex == 1) {
println("Yes selected")
}
else if(sender.selectedSegmentIndex == 2) {
println("No selected")
}
}
segCntrl.addTarget(self, action: "segmentorSwitch:", forControlEvents: UIControlEvents.ValueChanged)
Error code:
2015-07-07 11:46:24.482 myApp [75641:1855377] -[[myApp.SegViewControllerr segmentorSwitch:]: unrecognized selector sent to instance 0x7fbb0a43b450
2015-07-07 11:46:24.489 myApp[75641:1855377] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[myApp.SegViewController segmentorSwitch:]: unrecognized selector sent to instance 0x7fbb0a43b450'
* First throw call stack:
(
0 CoreFoundation 0x00000001060dcc65 exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010838abb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001060e40ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010603a13c ___forwarding_ + 988
4 CoreFoundation 0x0000000106039cd8 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001070bfd62 -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x00000001071d150a -[UIControl _sendActionsForEvents:withEvent:] + 467
7 UIKit 0x000000010724dfba -[UISegmentedControl _setSelectedSegmentIndex:notify:animate:] + 570
8 UIKit 0x000000010724ffbf -[UISegmentedControl touchesEnded:withEvent:] + 143
9 UIKit 0x000000010710c958 -[UIWindow _sendTouchesForEvent:] + 735
10 UIKit 0x000000010710d282 -[UIWindow sendEvent:] + 682
11 UIKit 0x00000001070d3541 -[UIApplication sendEvent:] + 246
12 UIKit 0x00000001070e0cdc _UIApplicationHandleEventFromQueueEvent + 18265
13 UIKit 0x00000001070bb59c _UIApplicationHandleEventQueue + 2066
14 CoreFoundation 0x0000000106010431 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
15 CoreFoundation 0x00000001060062fd __CFRunLoopDoSources0 + 269
16 CoreFoundation 0x0000000106005934 __CFRunLoopRun + 868
17 CoreFoundation 0x0000000106005366 CFRunLoopRunSpecific + 470
18 GraphicsServices 0x000000010cc5ba3e GSEventRunModal + 161
19 UIKit 0x00000001070be8c0 UIApplicationMain + 1282
20 myApp 0x0000000104d9a0c7 main + 135
21 libdyld.dylib 0x0000000109458145 start + 1
22 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Looks like segmentorSwitch: is implemented inside another method. Define it outside the method in which your code is contained, and this should be fixed.

Unrecognized selector sent to instance, Storyboard bug after connecting a button to view controller

I was messing with my storyboard with no code involved and got this error after I connected "Terms of use" button to a view controller. It was working fine before this action.
-I created and connected a class to Terms of Use View Controller
-I used action push segue to connect
2014-01-22 17:26:45.434 Project[1162:a0b] -[AboutViewController termsOfUseButton:]: unrecognized selector sent to instance 0x8c89d40
2014-01-22 17:26:45.437 Project[1162:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AboutViewController termsOfUseButton:]: unrecognized selector sent to instance 0x8c89d40'
*** First throw call stack:
(
0 CoreFoundation 0x0173b5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014be8b6 objc_exception_throw + 44
2 CoreFoundation 0x017d8903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0172b90b ___forwarding___ + 1019
4 CoreFoundation 0x0172b4ee _CF_forwarding_prep_0 + 14
5 libobjc.A.dylib 0x014d0874 -[NSObject performSelector:withObject:withObject:] + 77
6 UIKit 0x0022e0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
7 UIKit 0x0022e04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8 UIKit 0x003260c1 -[UIControl sendAction:to:forEvent:] + 66
9 UIKit 0x00326484 -[UIControl _sendActionsForEvents:withEvent:] + 577
10 UIKit 0x00325733 -[UIControl touchesEnded:withEvent:] + 641
11 UIKit 0x0026b51d -[UIWindow _sendTouchesForEvent:] + 852
12 UIKit 0x0026c184 -[UIWindow sendEvent:] + 1232
13 UIKit 0x0023fe86 -[UIApplication sendEvent:] + 242
14 UIKit 0x0022a18f _UIApplicationHandleEventQueue + 11421
15 CoreFoundation 0x016c483f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
16 CoreFoundation 0x016c41cb __CFRunLoopDoSources0 + 235
17 CoreFoundation 0x016e129e __CFRunLoopRun + 910
18 CoreFoundation 0x016e0ac3 CFRunLoopRunSpecific + 467
19 CoreFoundation 0x016e08db CFRunLoopRunInMode + 123
20 GraphicsServices 0x036909e2 GSEventRunModal + 192
21 GraphicsServices 0x03690809 GSEventRun + 104
22 UIKit 0x0022cd3b UIApplicationMain + 1225
23 Project 0x00003a9d main + 141
24 libdyld.dylib 0x01d77725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
(Lame but I found the solution after I finished writing the question)
The reason for this error is I created an IBAction-UIButton method on touch up inside.
I deleted that code and hoped the traces were deleted.
It seems it wasnt, I had to unconnect the touch up inside by clicking the X in red squared spot.
I would try recreating the button and the segue, maybe you changed the IBOutlet name by accident or any other thing.
GL HF

Resources