NSInvalidArgumentException after manually triggering seque

主宰稳场 提交于 2020-01-15 23:01:26

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/19982332/nsinvalidargumentexception-after-manually-triggering-seque

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!