0
votes

2020-02-17 23:12:31.949254+0100 LoyaltyCardsApp[64133:7104122] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[OTPViewController OTPPinInserted:pin:]: unrecognized selector sent to instance 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];

the crash occurs here:

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

other thing, I can't understand why in debug I can't go inside the if ..

if (self.delegate && [self.delegate respondsToSelector:@selector(OTPPinInserted:pin:)]){
    [self.delegate OTPPinInserted:self.insertOTP.input.text pin:pin];
}
1
i can't find where is the problem..Stefano
Where have you implemented the OTPPinInserted:pin method?AjinkyaSharma
The crash occurs + you cant enter that if block, because it is not able to find the OTPPinInserted:pin method implemented.AjinkyaSharma
Please check whether the delegate set properly, or the delegate is not deallocated. Also check whether the insertOTP is not null.shinoy
Always create delegate variable with weak property, the strong property will lead to memory issues.Kampai

1 Answers

1
votes

It is because you haven't implemented the OTPViewController protocol on the OTPViewController.

Or, more specifically, you need to implement this method:

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

(or spell it right if you did implement it. :).

Note that having capital letters prefixed on the method name is a little odd.

I'd stick with -pinInserted:pin:. If you have conflicting method declarations that typically indicates a different design problem.

If you do go the prefix route, then make it lowercase; -otpPinInserted:pin:.