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/