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.
screenshot1.gif
Swift ProgrammingiOS

Avatar of undefined
Last Comment
pgnatyuk
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

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.
Avatar of mmsi
mmsi

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mmsi
mmsi

ASKER

Thank you, this is the solution I was looking for.
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

You are welcome
iOS
iOS

iOS is a mobile operating system developed by Apple; it is a derivative of the Mac OS X desktop operating system, with which it shares many (but not all) common frameworks and other components. These include Cocoa Touch, the Mach/Darwin/XNU kernel and code from the Berkeley Software Distribution (BSD). Each iOS application runs in its own secure sandbox to prevent altering other applications, the operating system, or any other data.

4K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo