Fix for Terminating App Due to Uncaught Exception 'NSInvalidArgumentException'

I’ve been experimenting with a multiview iPhone / iOS app with a tab-based navigation and came across an error and solution for “unrecognized selector sent to instance.”

In one of the tab’s views I had a standard button with a Touch Up Inside event that I had connected to a buttonClicked method in the view’s controller.  For some reason, when I tapped that button the app would crash.  This was not happening when I built the same stuff in a single view app.

I went searching and was happy to find that the problem was well described and solved in the developer forums of MacNN.  It turns out that when you have have multiple view controllers for separate .xib files being controlled by a Tab Bar Controller you need to take an extra step of setting the Class Identity for that particular view. Here’s how:

  1. Open up MainWindow.xib in Interface Builder
  2. Expand the Tab Bar Controller item. (Your views are displayed)
  3. Single-click the controller containing your button.
  4. Hit ⌘-4 to bring up the Properties Inspector.
  5. Under Class Identity at the top, you’ll see the Class is set to UIViewController.  You need to use the dropdown to select the controller for that particular view.  In my case it was called SounderViewController, but it should match the name of the controller where your button clicked method is.

Voila.  Hope that helped you. If it did, please leave a comment. If it didn’t, please leave a comment.  Follow me on Twitter for iOS, music and life musings: @jetsetter.

2 thoughts on “Fix for Terminating App Due to Uncaught Exception 'NSInvalidArgumentException'”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>