I apologise ahead of time for the question title. I'm not quite sure how to succinctly describe my issue.
I'm having trouble with this delegate method I set up. I'm trying present a simple login screen modally. My issue is my login view gets a method called to it after I dismiss it.
Specifically, Xcode logs this:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LoginViewController login:]: unrecognized selector sent to instance [memory address]'
LoginViewController.h
#import <UIKit/UIKit.h>
@protocol LoginViewControllerProtocol;
@interface LoginViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *userNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *userPasswordTextField;
@property (weak, nonatomic) IBOutlet UIButton *loginButton;
@property (nonatomic, weak) NSObject<LoginViewControllerProtocol> *loginViewControllerDelegate;
@end
@protocol LoginViewControllerProtocol <NSObject>
- (void)loginViewController:(LoginViewController *)controller didLogin:(NSString *)userName;
@end
LoginViewController.m
- (IBAction)login
{
if ([self.loginViewControllerDelegate respondsToSelector:@selector(loginViewController:didLogin:)]) {
[self.loginViewControllerDelegate loginViewController:self didLogin:self.userNameTextField.text];
}
}
The delegate: (TestViewController.m)
- (void)loginViewController:(LoginViewController *)controller didLogin:(NSString *)userName
{
[self dismissModalViewControllerAnimated: YES];
didLogIn = YES;
}
I can't see why the delegate method is being sent back to the dismissed view.
Any help would be greatly appreciated!
Edit: I apologise for leaving this out. This occurs in the view controller that calls LoginViewController. The delegate method also exists here.
TestViewController.m
if (!didLogIn) {
//launch login view modally
LoginViewController* loginController = [[LoginViewController alloc] initWithNibName: @"LoginViewController" bundle: nil];
loginController.loginViewControllerDelegate = self;
loginController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
loginController.modalPresentationStyle = UIModalPresentationFormSheet;
NSLog(@"LoginViewControllerDelegate: %@", self.description);
NSLog(@"LoginViewController: %@", loginController.description);
[self presentModalViewController:loginController animated: YES];
TestViewController.h
#import <UIKit/UIKit.h>
#import "LoginViewController.h"
@class NuanceGuidHandler;
@interface TestViewController : UIViewController <LoginViewControllerProtocol>
@property (weak, nonatomic) IBOutlet UILabel *partnerGuidLabel;
@property (weak, nonatomic) IBOutlet UILabel *userGuidLabel;
@property (strong, nonatomic) NuanceGuidHandler *nuanceGuidHandler;
@property (nonatomic) BOOL didLogIn;
@end