Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storyboard custom class is ignored

Custom class input

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
like image 893
SimpleJ Avatar asked Jan 31 '26 05:01

SimpleJ


1 Answers

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

like image 143
solenoid Avatar answered Feb 01 '26 20:02

solenoid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!