ios - 无法识别的选择器发送到实例 obj c

标签 ios objective-c iphone xcode crash

2020-02-17 23:12:31.949254+0100 LoyaltyCardsApp[64133:7104122] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[OTPViewController OTPPinInserted:pin:]:无法识别的选择器发送到实例 0x7fd00a127730”

    @protocol OTPViewControllerDelegate
- (void) OTPAbortedByUser;
- (void) OTPPinInserted: (NSString *) pan pin: (NSString *) pin;


@end

@interface OTPViewController : UIViewController<KeyboardDelegate>

@property (nonatomic, strong) id delegate;

@property (nonatomic, weak) IBOutlet UIButton *confirmButton;
@property (weak, nonatomic) IBOutlet InputTextView *insertOTP;
@property (nonatomic, strong) NSString* stringInserted;
@property (weak, nonatomic) IBOutlet CopyableTextView *result;

@property (nonatomic, weak) IBOutlet NSLayoutConstraint *marginTop;

- (IBAction) clickOnDoneButton:(id)sender;
@end


- (void) pinInserted:(NSString *) pin{

    [self.delegate OTPPinInserted:self.insertOTP.input.text pin:pin];

崩溃发生在这里:
    [self.delegate OTPPinInserted:self.insertOTP.input.text pin:pin];

另一件事,我不明白为什么在调试中我不能进入 if ..
if (self.delegate && [self.delegate respondsToSelector:@selector(OTPPinInserted:pin:)]){
    [self.delegate OTPPinInserted:self.insertOTP.input.text pin:pin];
}

最佳答案

那是因为你还没有实现OTPViewController OTPViewController 上的协议(protocol).

或者,更具体地说,您需要实现此方法:

- (void) OTPPinInserted: (NSString *) pan pin: (NSString *) pin;

(或者如果您确实实现了它,则拼写正确。:)。

请注意,在方法名称前加上大写字母有点奇怪。

我会坚持 -pinInserted:pin: .如果您有冲突的方法声明,通常表明存在不同的设计问题。

如果您确实使用前缀路由,则将其设为小写; -otpPinInserted:pin: .

关于ios - 无法识别的选择器发送到实例 obj c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60271136/

相关文章:

ios - 不使用 Xcode 时将设备添加到配置文件

ios - 在完成处理程序中的 http 状态代码上隐藏进度条 - Swift 4

iphone - 在 iOS 中找不到框架 GoogleMaps sdk

ios - 通过阻止用户在同一设备上注册来防止滥用促销

objective-c - 如何在 UITextField 中只输入数字并限制最大长度?

ios - 如何增加角标(Badge)数量

ios - 如何在 Storyboard中自定义后退按钮

iphone - 如何使用来自 iPhone 应用程序的 FBConnect 在我的 feed-post 中包含一个链接?

ios - Swift 3 中的多个 CGAffineTransforms

移动网站上的 HTML/CSS 页脚在 iPhone safari 上不起作用如何修复?