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 Simple iPhone App with Objective-C Views and View Controllers View Controllers and IBAction

Anthony Williams
Anthony Williams
511 Points

App terminates with uncaught NSException

I am following the steps exactly but I keep getting this error, which also stops me from moving on. Here is the error that appeared in the console...Pleas help!:

2015-01-26 20:22:35.911 FunFacts[15281:728866] You pressed me! 2015-01-26 20:22:35.912 FunFacts[15281:728866] -[ViewController showFunFact:]: unrecognized selector sent to instance 0x7ff490726da0 2015-01-26 20:22:35.915 FunFacts[15281:728866] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController showFunFact:]: unrecognized selector sent to instance 0x7ff490726da0' *** First throw call stack: ( 0 CoreFoundation 0x0000000101407f35 exceptionPreprocess + 165 1 libobjc.A.dylib 0x00000001010a0bb7 objc_exception_throw + 45 2 CoreFoundation 0x000000010140f04d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x000000010136727c ___forwarding_ + 988 4 CoreFoundation 0x0000000101366e18 CF_forwarding_prep_0 + 120 5 UIKit 0x00000001017f58be -[UIApplication sendAction:to:from:forEvent:] + 75 6 UIKit 0x00000001018fc410 -[UIControl _sendActionsForEvents:withEvent:] + 467 7 UIKit 0x00000001018fb7df -[UIControl touchesEnded:withEvent:] + 522 8 UIKit 0x000000010183b308 -[UIWindow _sendTouchesForEvent:] + 735 9 UIKit 0x000000010183bc33 -[UIWindow sendEvent:] + 683 10 UIKit 0x00000001018089b1 -[UIApplication sendEvent:] + 246 11 UIKit 0x0000000101815a7d _UIApplicationHandleEventFromQueueEvent + 17370 12 UIKit 0x00000001017f1103 _UIApplicationHandleEventQueue + 1961 13 CoreFoundation 0x000000010133d551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION_ + 17 14 CoreFoundation 0x000000010133341d __CFRunLoopDoSources0 + 269 15 CoreFoundation 0x0000000101332a54 __CFRunLoopRun + 868 16 CoreFoundation 0x0000000101332486 CFRunLoopRunSpecific + 470 17 GraphicsServices 0x00000001049e99f0 GSEventRunModal + 161 18 UIKit 0x00000001017f4420 UIApplicationMain + 1282 19 FunFacts 0x0000000100b74bc3 main + 115 20 libdyld.dylib 0x0000000103997145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

9 Answers

Patrick Cooney
Patrick Cooney
12,216 Points

This is the important part of what you posted:

reason: '-[ViewController showFunFact:]: unrecognized selector sent to instance 0x7ff490726da0'

This error pops up a lot when you spell the name of the selector wrong or you get the capitalization wrong. The first thing I would do is check that you have spelled the selector name correctly. You may also want to post your code so people can look for other issues.

Anthony Williams
Anthony Williams
511 Points

Thanks for the info Patrick, and here is the rest of my code from ViewController.m and let me know if there is any other code you need to see, although this is the only thing I have made changes to.:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)showFunFact {
    NSLog(@"You pressed me!");
}




@end```
Patrick Cooney
Patrick Cooney
12,216 Points

This looks okay. I'm not sure what's going on. On closer inspection of your original post you get the expected output of "You pressed me!" before the error occurs. Just for the heck of it can you post the .h file?

Anthony Williams
Anthony Williams
511 Points

Also when i run the program it shows me this code from main.m, so i thought it might be useful:

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}
Patrick Cooney
Patrick Cooney
12,216 Points

Whenever you get an error it will always show this line. That's because this is the run loop of the app. Meaning all the events of the app funnel through this "main". This doesn't really tell you anything about what went wrong.

Anthony Williams
Anthony Williams
511 Points

Ok thanks for the info, and as requested here is the .h file:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UILabel *funFactLabel;

@end
Anthony Williams
Anthony Williams
511 Points

Yea I noticed i get the output at the top as well, but I think this same error prevents me from succeeding in the next lesson since the app terminates before it can call the new function (not sure what the correct name is) I wrote.

carlos carrillo
carlos carrillo
1,197 Points

I'm having the same issues, Its really frustrating as I cant continue with the lesson properly. My code is exactly like that above. checked it many times and still get the same result..

carlos carrillo
carlos carrillo
1,197 Points

solved this by saving my project file, I don't know if that was the problem but it certainly fixed this for me.

Anthony Williams
Anthony Williams
511 Points

After having someone who works on apps take a look at it, we couldn't figure out what was wrong and I simply started a new project. The new project doesn't have the issue, and I thank all of you for your help!

Amol Gupta
Amol Gupta
4,944 Points

This is crazy.I had the same problem, made a new project and followed the same steps and it worked this time.

Oliver Duncan
Oliver Duncan
16,642 Points

Make sure to select Arguments: none when adding the action to controller.