Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Vending Machine App in Swift 2.0 Displaying Additional Views Displaying Custom Views Modally

Becky Christofferson
Becky Christofferson
15,047 Points

Modal View Error

I successfully connected the get $5 dollars to the new view controller. The arrow shows correctly and seems to match the instructors. The app builds when I run it.

After I run it, when I click on the $5 the app crashes. It crashes and the xcode goes to the AppDelegate.swift file and highlights:

class AppDelegate: UIResponder, UIApplicationDelegate 

The console logs about 24 lines of codes but here's the first few lines (which seems to be the most important)

016-07-11 21:18:16.095 VendingMachine[2281:232794] -[VendingMachine.ViewController addBalance:]: unrecognized selector sent to instance 0x7fcc7b4a7170
2016-07-11 21:18:16.106 VendingMachine[2281:232794] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[VendingMachine.ViewController addBalance:]: unrecognized selector sent to instance 0x7fcc7b4a7170'
*** First throw call stack:

Not quite sure how to proceed because I'm not to delegates yet and my (brief) google search has not succeeded.

Any ideas would be great!

1 Answer

Martin Wildfeuer
PLUS
Martin Wildfeuer
Courses Plus Student 11,071 Points

This usually happens if you have removed/renamed an outlet/action either in Interface builder or in your class.

In Interface builder, open the utility view (it is the right column) and select the connections inspector (circled arrow in the upper right). Click through your views and check whether there are connections that are not supposed to be there. If yes, remove them by clicking the little x.

In your case, it seems to be [VendingMachine.ViewController addBalance:] the addBalance action.

Hope that helps :)