Hello having an issue with an unrecognized selector sent to an instance exception I have searched around a bit but I've been unable to find a solution.
The error I believe is occurring in my use of PureLayout but still unsure of what is specifically causing the issue. One weird thing is that after using Carthage to make my purelayout framework I had to use a weird bridging header in order to import purelayout usually you import PureLayout.h but my code would not compile unless I imported PureLayout_Ios/Purelayout.h in my bridging header. And so I have to import PureLayout_iOS in my viewcontroller.
View:
var presenter: SignUpPresenterProtocol?
//lazy var logoImageView: UIImageView = UIImageView()
lazy var nextButton: UIButton = {
var button = UIButton()
button.backgroundColor = Styles.BUTTON_COLOR
return button
}()
override func viewDidLoad() {
super.viewDidLoad()
self.setupSubviews()
self.setupConstraints()
self.setNeedsStatusBarAppearanceUpdate()
self.presenter?.viewDidLoad()
}
private func setupSubviews()
{
self.view.addSubview(self.nextButton)
self.view.addSubview(self.userNameTextField)
self.nextButton.addTarget(self, action: Selector("userDidSelectNext:"), forControlEvents: UIControlEvents.TouchUpInside)
//self.view.addSubview(self.logoImageView)
}
private func setupConstraints()
{
self.nextButton.translatesAutoresizingMaskIntoConstraints = false
self.nextButton.autoMatchDimension(.Width, toDimension: .Width, ofView: self.view, withMultiplier: 0.8)
self.nextButton.autoSetDimension(.Height, toSize: Styles.BUTTON_HEIGHT)
self.nextButton.autoCenterInSuperview()x
}
func userDidSelectNext(sender: AnyObject)
{
self.presenter?.userDidSelectNext()
}
And here is the error stack trace:
2015-07-28 08:51:58.218 app[10795:507285] -[UIButton autoMatchDimension:toDimension:ofView:withMultiplier:]: unrecognized selector sent to instance 0x7f9d02f8cad0
2015-07-28 08:51:58.222 app[10795:507285] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton autoMatchDimension:toDimension:ofView:withMultiplier:]: unrecognized selector sent to instance 0x7f9d02f8cad0'
*** First throw call stack:
(
0 CoreFoundation 0x00000001079e18b5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001095c1df3 objc_exception_throw + 48
2 CoreFoundation 0x00000001079e9ead -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010793819a ___forwarding___ + 970
4 CoreFoundation 0x0000000107937d48 _CF_forwarding_prep_0 + 120
5 app 0x0000000107324984 _TFC7app12UsernameViewP33_A6105A8D44322785BCD6FD80914CAE7C16setupConstraintsfS0_FT_T_ + 180
6 app 0x000000010732422d _TFC7app12UsernameView11viewDidLoadfS0_FT_T_ + 93
7 app 0x0000000107324312 _TToFC7app12UsernameView11viewDidLoadfS0_FT_T_ + 34
8 UIKit 0x000000010837fa6e -[UIViewController loadViewIfRequired] + 860
9 UIKit 0x000000010837fdbd -[UIViewController view] + 27
10 UIKit 0x00000001082607e4 -[UIWindow addRootViewControllerViewIfPossible] + 61
11 UIKit 0x0000000108260ee1 -[UIWindow _setHidden:forced:] + 302
12 UIKit 0x00000001082726fc -[UIWindow makeKeyAndVisible] + 43
13 app 0x0000000107326afc _TFC7app11AppDelegate11applicationfS0_FTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVSs10DictionaryCSo8NSObjectPSs9AnyObject____Sb + 588
14 app 0x0000000107326c43 _TToFC7app11AppDelegate11applicationfS0_FTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVSs10DictionaryCSo8NSObjectPSs9AnyObject____Sb + 179
15 UIKit 0x00000001081f2bc4 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 272
16 UIKit 0x00000001081f3cea -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3287
17 UIKit 0x00000001081f9e97 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1755
18 UIKit 0x00000001081f7635 -[UIApplication workspaceDidEndTransaction:] + 188
19 FrontBoardServices 0x000000010c2b0b5e -[FBSSerialQueue _performNext] + 192
20 FrontBoardServices 0x000000010c2b0ecc -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x000000010790e171 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x000000010790409c __CFRunLoopDoSources0 + 556
23 CoreFoundation 0x0000000107903553 __CFRunLoopRun + 867
24 CoreFoundation 0x0000000107902f68 CFRunLoopRunSpecific + 488
25 UIKit 0x00000001081f6fd2 -[UIApplication _run] + 402
26 UIKit 0x00000001081fb6f8 UIApplicationMain + 171
27 app 0x0000000107327e0d main + 109
28 libdyld.dylib 0x000000010a5f892d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
thank you guys!
Try replacing this line...
self.nextButton.addTarget(self, action: Selector("userDidSelectNext:"), forControlEvents: UIControlEvents.TouchUpInside)
with this instead...
self.nextButton.addTarget(self, action: "userDidSelectNext:", forControlEvents: UIControlEvents.TouchUpInside)
You can find more info in the apple document here: Objective C Selectors
After using carthage to update my purelayout library it was fixed, not sure what the issue was though, here is the latest changlog on github.
Related
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.
This is the code that I tried running on Xcode and the idea is when I press the button, it will show the background and the logo, however when I press the button, it just leads me straight into the error
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var coolLogo: UIImageView!
#IBOutlet weak var coolBg: UIImageView!
#IBOutlet weak var uncoolButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
#IBAction func makeMeNotSoUncoolButton(sender: AnyObject) {
coolLogo.hidden = false
coolBg.hidden = false
uncoolButton.hidden = true
print ("Its running")
}
}
This is the error that I got
2016-06-29 10:19:01.229 SuperCool[1950:40240] -
[SuperCool.ViewController uncoolButton:]: unrecognized selector sent to instance 0x7fc4e9544fc0
2016-06-29 10:19:01.238 SuperCool[1950:40240] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SuperCool.ViewController uncoolButton:]: unrecognized selector sent to instance 0x7fc4e9544fc0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010f617d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001113bbdeb objc_exception_throw + 48
2 CoreFoundation 0x000000010f620d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010f566cfa ___forwarding___ + 970
4 CoreFoundation 0x000000010f5668a8 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010fe41a8d -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x000000010ffb4e67 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x000000010ffb5143 -[UIControl _sendActionsForEvents:withEvent:] + 327
8 UIKit 0x000000010ffb4263 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x000000010feb499f -[UIWindow _sendTouchesForEvent:] + 835
10 UIKit 0x000000010feb56d4 -[UIWindow sendEvent:] + 865
11 UIKit 0x000000010fe60dc6 -[UIApplication sendEvent:] + 263
12 UIKit 0x000000010fe3a553 _UIApplicationHandleEventQueue + 6660
13 CoreFoundation 0x000000010f53d301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010f53322c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x000000010f5326e3 __CFRunLoopRun + 867
16 CoreFoundation 0x000000010f5320f8 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x0000000113cadad2 GSEventRunModal + 161
18 UIKit 0x000000010fe3ff09 UIApplicationMain + 171
19 SuperCool 0x000000010f432422 main + 114
20 libdyld.dylib 0x0000000111e7f92d start + 1
21 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Looks like you connected either the uncoolButton outlet or the makeMeNotSoUncoolButton action incorrectly.
Just place brakepoint in that method and check your self class and class of your button, than you will know what isn't as you expected. You can check class using method class, that returns instance of your clas, than just print it to log.
I am creating an app where I need a button that generates more buttons. I have my code like this:
func showButtons(array:Array<UIButton>)
{
for(var i:Int = 0; i < array.count; i++)
{
array[i].setImage(UIImage(named: "StartButton.png"), forState: UIControlState.Normal)
array[i].frame = CGRectMake(CGFloat(arc4random_uniform(200)), CGFloat(arc4random_uniform(200)), 100, 100)
array[i].addTarget(self, action: "pressed", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(array[i])
}
}
The pressed button is this:
func pressed(sender:AnyObject?)
{
maybe()
}
But I know that is not the problem because another button, which was not create programmatically and has it's own action function, uses the same function and does not crash.
My crash report is here:
(104.0, 70.0)
2016-02-02 10:34:11.267 Test[5150:1087940] -[Test.ViewController pressed]: unrecognized selector sent to instance 0x7f8a8ac3be90
2016-02-02 10:34:11.283 Test[5150:1087940] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Test.ViewController pressed]: unrecognized selector sent to instance 0x7f8a8ac3be90'
* First throw call stack:
(
0 CoreFoundation 0x0000000101c81e65 exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001039c1deb objc_exception_throw + 48
2 CoreFoundation 0x0000000101c8a48d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000101bd790a ___forwarding_ + 970
4 CoreFoundation 0x0000000101bd74b8 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001024a0194 -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x000000010260f6fc -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x000000010260f9c8 -[UIControl _sendActionsForEvents:withEvent:] + 311
8 UIKit 0x000000010260eaf8 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x000000010250f49b -[UIWindow _sendTouchesForEvent:] + 835
10 UIKit 0x00000001025101d0 -[UIWindow sendEvent:] + 865
11 UIKit 0x00000001024beb66 -[UIApplication sendEvent:] + 263
12 UIKit 0x0000000102498d97 _UIApplicationHandleEventQueue + 6844
13 CoreFoundation 0x0000000101bada31 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
14 CoreFoundation 0x0000000101ba395c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x0000000101ba2e13 __CFRunLoopRun + 867
16 CoreFoundation 0x0000000101ba2828 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x0000000106297ad2 GSEventRunModal + 161
18 UIKit 0x000000010249e610 UIApplicationMain + 171
19 Test 0x0000000101aa134d main + 109
20 libdyld.dylib 0x00000001044ca92d start + 1
21 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I believe my problem is I have all of e buttons attached to the action "pressed" so it sends a crash. Does anyone know a way to fix this/replace this. I have looked at the posts showing how to programmatically make a UIButton in Swift.
Your code has not problem at all with the number of UIButton associated to the same function, you're missing the colon at the end of the selector for the UIBUtton as your function receive a parameter in his signature, so you need to change the following line:
array[i].addTarget(self, action: "pressed:", forControlEvents:.TouchUpInside)
I hope this help you.
thanks to God (or Latter... ) now on Xcode 8 / Swift 3 syntax is cleaner, so no need to add (:_); compiler will find the method.
so the following code works fine:
override func viewDidLoad() {
super.viewDidLoad()
btn.addTarget(self, action: #selector(buttonTapped), for: UIControlEvents.touchUpInside)
}
final func buttonTapped(sender: UIButton){
}
if You try to mess compiler, i.e:
final func buttonTapped(sender: UIButton. fake: int){..
You will be called (as signature is correct..) but the parameter "fake" will get garbage from stack.
Of course:
final func buttonTapped(){..
works and is called. (no param is taken from stack).
By the way I prefer old syntax that required multiple ":" for every param, as per previous code:
"pressed:"
I'm using Xcode 6.4 and get the following error when trying to use a use a back button I hard coded:
2015-07-01 22:41:47.082 oby[14979:280903] -[oby.PhotoViewController popView]: unrecognized selector sent to instance 0x7f8112f24d90
2015-07-01 22:41:47.103 oby[14979:280903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[oby.PhotoViewController popView]: unrecognized selector sent to instance 0x7f8112f24d90'
*** First throw call stack:
(
0 CoreFoundation 0x0000000105b92c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001076fdbb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000105b9a0ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000105af013c ___forwarding___ + 988
4 CoreFoundation 0x0000000105aefcd8 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000106432d62 -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x000000010654450a -[UIControl _sendActionsForEvents:withEvent:] + 467
7 UIKit 0x00000001065438d9 -[UIControl touchesEnded:withEvent:] + 522
8 UIKit 0x000000010647f958 -[UIWindow _sendTouchesForEvent:] + 735
9 UIKit 0x0000000106480282 -[UIWindow sendEvent:] + 682
10 UIKit 0x0000000106446541 -[UIApplication sendEvent:] + 246
11 UIKit 0x0000000106453cdc _UIApplicationHandleEventFromQueueEvent + 18265
12 UIKit 0x000000010642e59c _UIApplicationHandleEventQueue + 2066
13 CoreFoundation 0x0000000105ac6431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x0000000105abc2fd __CFRunLoopDoSources0 + 269
15 CoreFoundation 0x0000000105abb934 __CFRunLoopRun + 868
16 CoreFoundation 0x0000000105abb366 CFRunLoopRunSpecific + 470
17 GraphicsServices 0x000000010a676a3e GSEventRunModal + 161
18 UIKit 0x00000001064318c0 UIApplicationMain + 1282
19 oby 0x00000001053502b7 main + 135
20 libdyld.dylib 0x0000000107e33145 start + 1
21 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Button:
let btn = UINavButton(title: "Back", direction: UIButtonDirection.Left, parentView: self.view)
btn.addTarget(self, action: "popView", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(btn)
Could someone help me fix this please?
Thank you!
Something like this
btn.addTarget(self, action: "backAction", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(btn)
func backAction() {
self.navigationController?.popViewControllerAnimated(true)
}
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.