gpt4 book ai didi

ios - Storyboard自定义类被忽略

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:31:58 26 4
gpt4 key购买 nike

Custom class input

我正在尝试将自定义 View Controller 添加到我的 Storyboard 中。 View Controller KTResearchUploadViewController 出现在“自定义类”类下拉列表中,我已选择它。在 View Controller 内(在 Storyboard上),我有一个链接到 KTResearchUploadViewController 的按钮,用于在主要操作上调用方法 handleUploadButtonPress

按下按钮时,我收到此错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController handleUploadButtonPress:]: unrecognized selector sent to instance 0x11c33b740'

看起来它试图在 UIViewController 而不是 KTResearchUploadViewController 上调用 handleUploadButtonPress。我在这里做错了什么?

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

最佳答案

将 IBAction 添加到您的 .h

#import <UIKit/UIKit.h>

@interface KTResearchUploadViewController : UIViewController
- (IBAction)handleUploadButtonPress:(id)sender;
@end

还要确保从 IB 中的按钮到您的代码有连接

https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ConnectTheUIToCode.html

关于ios - Storyboard自定义类被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45869320/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com