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

unrecognized selector sent to instance obj c

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协议。

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

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

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

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

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

如果你确实走前缀路线,那就把它变成小写; -otpPinInserted:pin:.