R kanojia
R kanojia

Reputation: 105

Click button getting error : unrecognized selector sent to instance - IOS Swift 3

Click button getting error : unrecognized selector sent to instance - IOS Swift 3

import UIKit
class Login: UIViewController {
override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func LoginButton(_ sender: UIButton) {
    print("Login button")
}}

Error 2017-04-05 14:55:56.965 Design[3510:67974] Unknown class Login in Interface Builder file. 2017-04-05 14:56:00.084 Design[3510:67974] -[UIView LoginButton:]: unrecognized selector sent to instance 0x7ffa2f70c9b0 2017-04-05 14:56:00.093 Design[3510:67974] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView LoginButton:]: unrecognized selector sent to instance 0x7ffa2f70c9b0' * First throw call stack: ( .... ) libc++abi.dylib: terminating with uncaught exception of type NSException

Image : enter image description here I am beginner in IOS app development

Upvotes: 2

Views: 3462

Answers (6)

mattiasnilssons
mattiasnilssons

Reputation: 1

I solved it by going to the "Show the Connections inspector" when you have the button selectedhere is my weather app. Take away any connections from the button there and start again!

Upvotes: 0

R kanojia
R kanojia

Reputation: 105

I solved Thanks to everyone, Problem was when i am making connection - On object selection there was to 2 options First VC controller "Login" and second one only "Login" (default selecting). I just changed defualt "Login" to VC "Login".

Default object

2 types of options

After selected VC Login

Upvotes: 0

Vignesh J
Vignesh J

Reputation: 257

You must be check the classname and module. If the module is displayed in place holder or Empty.Click the module check box and dropdown will be displayed with your app name now you will select the option.And give the Storyboard id. Now run your coding.

enter image description here

Upvotes: 2

Basir Alam
Basir Alam

Reputation: 1358

Got your problem you have not included navigation controller in your storyboard and you are trying to push from segue. But you have posted the code for button action. Add navigation controller to your storyboard first. Remove manual segue from login button to any storyboard.

If you don't know how to add navigation bar the follow the image: enter image description here

Upvotes: 1

Nishant Bhindi
Nishant Bhindi

Reputation: 2252

You most likely forgot to set your custom view controller class to match the one you created in the storyboard

If you already set your custom view controller class than reset that and remove IBAction connection and reconnect it.

Upvotes: 1

devang bhatt
devang bhatt

Reputation: 470

Try to reconnect @IBAction Method

@IBAction func LoginButton(_ sender: UIButton) {
        print("Login button")
}

and if it's not working can you please show image of your Stroyboard and connection that you have done with your button

Upvotes: 0

Related Questions