Jeroen van den Broek
Jeroen van den Broek

Reputation: 863

NSInvalidArgumentException after manually triggering seque

I'm in the "awesome" position to have to support someone else's code even though before this project I have never worked in objective C or made iOS apps, so please excuse me if I'm doing something really obvious or stupid.

I needed a new view controller with a custom class. First I drew the view on my storyboard. Then I created a new class which I derived off of UIViewController. Then, I set the view's custom class to this new class I made. I hooked up the single button on the view to the code so I could make it close the view, then I made a (manual/modal) segue so I could call this new view from my main menu. All of this should be hooked up fine because I've used it before, but I'll show you how I call the segue anyway:

[self performSegueWithIdentifier:@"ScoreCard" sender:self];

Now, my problem is that when I press the button to run the above, I get the following error:

-[Scores _setViewDelegate:]: unrecognized selector sent to instance 0x9b4c460

Scores is the name of my custom UIViewController class. Its .h file looks pretty simple for now:

#import <UIKit/UIKit.h>

@interface Scores : UIViewController

- (IBAction)goBack:(id)sender;

@end

The .m file doesn't do anything besides what Xcode put in there by default and my implementation of goBack:

- (IBAction)goBack:(id)sender
{
    [self dismissModalViewControllerAnimated:YES];
}

Does anyone know what I'm forgetting? I successfully added another view controller yesterday in the same way and that one works just fine. Why doesn't this one?

Upvotes: 1

Views: 121

Answers (1)

rdelmar
rdelmar

Reputation: 104092

The error that you're getting, -[Scores _setViewDelegate:]: unrecognized selector..., seems to be caused by setting the class of a UIView to a class that's not a subclass of UIView. Make sure that you've set the class for your view controller, not the view, to your custom class.

Upvotes: 2

Related Questions