Xcode strange error when button is pressed - ios

So my Swift program in Xcode 6.4 is working fine, until I click one of my buttons in particular. When I click it, the simulator crashes and the following is printed to the console:
2015-08-12 21:41:08.323 Unit Hero 2.0[2549:99472] -[Unit_Hero_2_0.ViewController finalUnitsButton:]: unrecognized selector sent to instance 0x7faf20675d10
2015-08-12 21:41:08.326 Unit Hero 2.0[2549:99472] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Unit_Hero_2_0.ViewController finalUnitsButton:]: unrecognized selector sent to instance 0x7faf20675d10'
*** First throw call stack:
0 CoreFoundation 0x000000010b630c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010d19bbb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010b6380ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010b58e13c ___forwarding___ + 988
4 CoreFoundation 0x000000010b58dcd8 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010bed0d62 -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x000000010bfe250a -[UIControl _sendActionsForEvents:withEvent:] + 467
7 UIKit 0x000000010bfe18d9 -[UIControl touchesEnded:withEvent:] + 522
8 UIKit 0x000000010bf1d958 -[UIWindow _sendTouchesForEvent:] + 735
9 UIKit 0x000000010bf1e282 -[UIWindow sendEvent:] + 682
10 UIKit 0x000000010bee4541 -[UIApplication sendEvent:] + 246
11 UIKit 0x000000010bef1cdc _UIApplicationHandleEventFromQueueEvent + 18265
12 UIKit 0x000000010becc59c _UIApplicationHandleEventQueue + 2066
13 CoreFoundation 0x000000010b564431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010b55a2fd __CFRunLoopDoSources0 + 269
15 CoreFoundation 0x000000010b559934 __CFRunLoopRun + 868
16 CoreFoundation 0x000000010b559366 CFRunLoopRunSpecific + 470
17 GraphicsServices 0x000000010f604a3e GSEventRunModal + 161
18 UIKit 0x000000010becf8c0 UIApplicationMain + 1282
19 Unit Hero 2.0 0x000000010b4251c7 main + 135
20 libdyld.dylib 0x000000010d8d1145 start + 1
libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
And here is the code for the button in question:
#IBAction func newCalculationButton(sender: AnyObject)
{
if (equation.count != 0) //empties arrays to prepare for a new calculation
{
equation.removeAll()
}
if (unitsOriginal.count != 0)
{
unitsOriginal.removeAll()
}
if (operations.count != 0)
{
operations.removeAll()
}
if (numerator.count != 0)
{
numerator.removeAll()
}
if (denominator.count != 0)
{
denominator.removeAll()
}
if (largestComponent.count != 0)
{
largestComponent.removeAll()
}
finalNumerator = nil
finalDenominator = nil
isNilNumerator = 0 //counter for number of nil items in numerator
isNilDenominator = 0 //counter for number of nil items in denominator
mainLabel.text = ""
}
What exception could it be referring to? The code is pretty simple, I'm not sure what could be wrong. Any insight is much appreciated!

Some times we copy paste button and Xcode keeps old references (actions and outlets). Check it:
Check all Outlets (IB)
Check all Actions (IB)

Related

Error while Changing the image of the button from an image to another when clicked on the button

Here is my code :
#IBAction func moreClicked(_ sender: UIButton) {
if sender.currentImage == #imageLiteral(resourceName: "more_off"){
sender.setImage(#imageLiteral(resourceName: "more_on"), for: .normal)
}
else
{
sender.setImage(#imageLiteral(resourceName: "more_off"), for: .normal)
}
}
I am getting this error:
2018-09-05 11:03:28.708661+0530 musicPlayer[25450:590989]
-[musicPlayer.SecondViewController more:]: unrecognized selector sent to instance 0x7fc1d4606d00
2018-09-05 11:03:28.715659+0530 musicPlayer[25450:590989] *
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason:
'-[musicPlayer.SecondViewController more:]: unrecognized selector sent
to instance 0x7fc1d4606d00'
* First throw call stack: ( 0 CoreFoundation 0x00000001087ea1e6 exceptionPreprocess + 294 1 libobjc.A.dylib
0x0000000107a36031 objc_exception_throw + 48 2 CoreFoundation
0x000000010886b784 -[NSObject(NSObject) doesNotRecognizeSelector:] +
132 3 UIKit 0x0000000108e956db
-[UIResponder doesNotRecognizeSelector:] + 295 4 CoreFoundation 0x000000010876c898 ___forwarding_ + 1432 5 CoreFoundation
0x000000010876c278 _CF_forwarding_prep_0 + 120 6 UIKit
0x0000000108c683e8 -[UIApplication sendAction:to:from:forEvent:] + 83
7 UIKit 0x0000000108de37a4
-[UIControl sendAction:to:forEvent:] + 67 8 UIKit 0x0000000108de3ac1 -[UIControl _sendActionsForEvents:withEvent:] + 450
9 UIKit 0x0000000108de2a09
-[UIControl touchesEnded:withEvent:] + 580 10 UIKit 0x0000000108cdd0bf -[UIWindow _sendTouchesForEvent:] + 2729 11 UIKit
0x0000000108cde7c1 -[UIWindow sendEvent:] + 4086 12 UIKit
0x0000000108c82310 -[UIApplication sendEvent:] + 352 13 UIKit
0x00000001095c36af dispatchPreprocessedEventFromEventQueue + 2796
14 UIKit 0x00000001095c62c4
__handleEventQueueInternal + 5949 15 CoreFoundation 0x000000010878cbb1
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 16 CoreFoundation 0x00000001087714af
__CFRunLoopDoSources0 + 271 17 CoreFoundation 0x0000000108770a6f __CFRunLoopRun + 1263 18 CoreFoundation
0x000000010877030b CFRunLoopRunSpecific + 635 19 GraphicsServices
0x000000010ff76a73 GSEventRunModal + 62 20 UIKit
0x0000000108c67057 UIApplicationMain + 159 21 musicPlayer
0x000000010711cc27 main + 55 22 libdyld.dylib
0x000000010cd4f955 start + 1 ) libc++abi.dylib: terminating with
uncaught exception of type NSException
2018-09-05 11:03:28.708661+0530 musicPlayer[25450:590989]
-[musicPlayer.SecondViewController more:]: unrecognized selector sent to instance 0x7fc1d4606d00
The above message means that SecondViewController expects to have method called more: but when the action is triggered and instance from this class tries to find the more: method, it does not recognise such method and the application crashes.
What I think has happened here is: you have dragged action from your Xib/Storyboard to your VC class and named it more:. After this you have renamed it manually (not Refactor > Rename) to moreClicked:. This way the IBAction of the SecondViewController still points to method that is called more:, however your class does not have such method anymore.
So basically, you need to remove the already existing reference of the IBAction from your xib/storyboard and reconnect it with the new method: moreClicked:, and all should be working.

NSUndoManager errors with "unrecognized selector sent to instance"

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

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.

signal SIGARBT error

I get this error if I'll run my App in the iOS Simulator (iPhone 4-inch 32-bit iOS 7.1):
Thread 1: signal SIGABRT
Error:
int main(int argc, char * argv[])
{
#autoreleasepool
{
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
I hope someone can help me.
Console Report:
2014-04-26 14:09:24.039 Picxxr[2184:60b] -[ViewController filter1:]: unrecognized selector sent to instance 0x964d580
2014-04-26 14:09:24.041 Picxxr[2184:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController filter1:]: unrecognized selector sent to instance 0x964d580'
*** First throw call stack:
(
0 CoreFoundation 0x01d651e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01ae48e5 objc_exception_throw + 44
2 CoreFoundation 0x01e02243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01d5550b ___forwarding___ + 1019
4 CoreFoundation 0x01d550ee _CF_forwarding_prep_0 + 14
5 libobjc.A.dylib 0x01af6880 -[NSObject performSelector:withObject:withObject:] + 77
6 UIKit 0x007a63b9 -[UIApplication sendAction:to:from:forEvent:] + 108
7 UIKit 0x007a6345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8 UIKit 0x008a7bd1 -[UIControl sendAction:to:forEvent:] + 66
9 UIKit 0x008a7fc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
10 UIKit 0x008a7243 -[UIControl touchesEnded:withEvent:] + 641
11 UIKit 0x00b3c2e3 _UIGestureRecognizerUpdate + 7166
12 UIKit 0x007e5a5a -[UIWindow _sendGesturesForEvent:] + 1291
13 UIKit 0x007e6971 -[UIWindow sendEvent:] + 1021
14 UIKit 0x007b85f2 -[UIApplication sendEvent:] + 242
15 UIKit 0x007a2353 _UIApplicationHandleEventQueue + 11455
16 CoreFoundation 0x01cee77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
17 CoreFoundation 0x01cee10b __CFRunLoopDoSources0 + 235
18 CoreFoundation 0x01d0b1ae __CFRunLoopRun + 910
19 CoreFoundation 0x01d0a9d3 CFRunLoopRunSpecific + 467
20 CoreFoundation 0x01d0a7eb CFRunLoopRunInMode + 123
21 GraphicsServices 0x032155ee GSEventRunModal + 192
22 GraphicsServices 0x0321542b GSEventRun + 104
23 UIKit 0x007a4f9b UIApplicationMain + 1225
24 Picxxr 0x0000cd7d main + 141
25 libdyld.dylib 0x03e0c701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Filter1 in a class called ViewController doesn't exist. You may have deleted an outlet or something from the code, but forgot to delete the link from the actual object in the storyboard. Right click on what was linked to Filter1 and see if it has the old (deleted) connection still.
It looks like you setup a button with an action of filter1: but you never added the filter1: method to your ViewController class.
Perhaps you defined the method as filter1 instead of filter1:. The colon makes a huge difference.
If your method is really:
- (IBAction)filter1 {
}
Then you need to change the button to use the selector filter1 instead of filter1:. Or change the method to:
- (IBAction)filter1:(id)sender {
}

SIGABRT error - segmented control

i have a segmented control which, depending on what is selected, is meant to allocate a value to a NS string, as follows:
-(IBAction)driverKnownIndexChanged{
switch (self.driverKnown.selectedSegmentIndex) {
case 0:
driverKnownResponse = #"Yes";
break;
case 1:
driverKnownResponse = #"No";
break;
default:
break;
}
}
however, it is throwing a SIGABRT at the following line:
#import "RoadSafetyAppAppDelegate.h"
int main(int argc, char * argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([RoadSafetyAppAppDelegate class]));
}
}
and here is the console output:
2014-01-30 13:32:16.403 Road Safety App V2[3873:70b] -[DobInAHoonViewController driverKnown:]: unrecognized selector sent to instance 0xcd23440
2014-01-30 13:32:16.409 Road Safety App V2[3873:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DobInAHoonViewController driverKnown:]: unrecognized selector sent to instance 0xcd23440'
*** First throw call stack:
(
0 CoreFoundation 0x01d8f7e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01b0f8e5 objc_exception_throw + 44
2 CoreFoundation 0x01e2c843 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01d7fb0b ___forwarding___ + 1019
4 CoreFoundation 0x01d7f6ee _CF_forwarding_prep_0 + 14
5 libobjc.A.dylib 0x01b2182b -[NSObject performSelector:withObject:] + 70
6 UIKit 0x007d8309 -[UIApplication sendAction:to:from:forEvent:] + 108
7 UIKit 0x007d8295 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8 UIKit 0x008d90a1 -[UIControl sendAction:to:forEvent:] + 66
9 UIKit 0x008d9496 -[UIControl _sendActionsForEvents:withEvent:] + 577
10 UIKit 0x008d90d6 -[UIControl sendActionsForControlEvents:] + 48
11 UIKit 0x00947572 -[UISegmentedControl _setSelectedSegmentIndex:notify:animate:] + 598
12 UIKit 0x009498c3 -[UISegmentedControl touchesEnded:withEvent:] + 175
13 UIKit 0x00b6ccc3 _UIGestureRecognizerUpdate + 7166
14 UIKit 0x008177ca -[UIWindow _sendGesturesForEvent:] + 1291
15 UIKit 0x008186e1 -[UIWindow sendEvent:] + 1021
16 UIKit 0x007ea542 -[UIApplication sendEvent:] + 242
17 UIKit 0x007d42f3 _UIApplicationHandleEventQueue + 11455
18 CoreFoundation 0x01d18d7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
19 CoreFoundation 0x01d1870b __CFRunLoopDoSources0 + 235
20 CoreFoundation 0x01d357ae __CFRunLoopRun + 910
21 CoreFoundation 0x01d34fd3 CFRunLoopRunSpecific + 467
22 CoreFoundation 0x01d34deb CFRunLoopRunInMode + 123
23 GraphicsServices 0x0344f4ed GSEventRunModal + 192
24 GraphicsServices 0x0344f32a GSEventRun + 104
25 UIKit 0x007d6eeb UIApplicationMain + 1225
26 Road Safety App V2 0x00002f9d main + 141
27 libdyld.dylib 0x0308470d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
and Ideas as to why i am having this problem? and a solution would also be appreciated.
This line switch (self.driverKnown.selectedSegmentIndex) { is accessing a property named driverKnown but that driver is unknown. The stack trace and exception are telling you that driverKnown is an undeclared or unknock getter method for the property.
The exception calls out DobInAHoonViewController which in that line of code would be the self. Is driverKnown suppose to be the name of your UISegmentedControl? Can we see the creation of said UISegmentedControl?
your method doesn't know selectedSegmentIndex . because you not value of segment value changed
UISegmentControl *mySegmentedControl = [[UISegmentControl alloc]init];
[mySegmentedControl addTarget:self action:#selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];
- (IBAction)segmentValueChanged:(id)sender {
UISegmentedControl *driverKnown = (UISegmentedControl *)sender;
switch (driverKnown.selectedSegmentIndex) {
case 0:
driverKnownResponse = #"Yes";
break;
case 1:
driverKnownResponse = #"No";
break;
default:
break;
}
}

Resources