
I'm attempting to add a custom view controller to my storyboard. The view controller KTResearchUploadViewController appears in the "Custom Class" class dropdown, and I have selected it. Inside the view controller (on the storyboard), I have a button that is linked to KTResearchUploadViewController to call a method handleUploadButtonPress on primary action.
When the button is pressed, I receive this error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController handleUploadButtonPress:]: unrecognized selector sent to instance 0x11c33b740'
It looks like it's trying to call handleUploadButtonPress on UIViewController rather than KTResearchUploadViewController. What am I doing wrong here?
KTResearchUploadViewController.h
#import <UIKit/UIKit.h>
@interface KTResearchUploadViewController : UIViewController
@end
KTResearchUploadViewController.m
#import "KTResearchUploadViewController.h"
@interface KTResearchUploadViewController ()
@end
@implementation KTResearchUploadViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)handleUploadButtonPress:(id)sender {
NSLog(@"Button pressed!");
}
@end
Add the IBAction to your .h
#import <UIKit/UIKit.h>
@interface KTResearchUploadViewController : UIViewController
- (IBAction)handleUploadButtonPress:(id)sender;
@end
Also make sure there is a connection from your button in IB to your code
https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ConnectTheUIToCode.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With