Avatar of mmsi
mmsi asked on

Error: unrecognized selector

I'm taking a course online, and working through my very first IOS project.

Topic: Buttons and IBaction

when stepping through the project to create an IBaction for my button. I notice the code in the training video was different than the code my xcode generated when dragging a button from the storyboard to the viewcontroller.

So I deleted the code that I generated from the veiwcontroller.h and .m file and started the process over again.  

Ever since I deleted the code,  the program will not work.  In the simulator when I click my button i get an error.

I tried doing a clean build (command-option-shift-k) that did not work.  I deleted the code again, and ran it through the simulator and when I click the button it still crashes.

I know if I delete the project and start over it would work.  But I am more interested in finding what went wrong and how can I fix this solution in the future.

I attached the error message.
Swift ProgrammingiOS

Avatar of undefined
Last Comment

8/22/2022 - Mon

When Xcode generated a code for you - an method that is called when the user clicks on the button - this IBAction, it connected the button you see on the screen with your project (visually there was a dot before text '- IBAction'). You deleted the code but you didn't deleted the connection points. When you added a new method, probably, you didn't connect it with the
button on the screen. You can do it and it will fix your current project.

Maybe, at this stage, it can be easier and faster to re-create the project and do everything again.

I was playing around with the project, and realized that if I could just delete the button the button off the storyboard.

Question: Where are the connection points that you mention?

For example: C#

If I drag a button to the form and create a click event.  Visual Studio generates EventHandlers for me.  So If I delete the click event, then compile the program crashes.  I would then just delete the EventHandler that visual studio created, and then recompile the error would go away.

Is this a similar situation?  Where xcode is creating some kind of connection, that I can just delete and the error would go away?  I deleted the code I generated, but I am not sure why the error is occurring when the code is gone.

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Thank you, this is the solution I was looking for.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

You are welcome