Reputation: 21
I have typed this into my .m file - StudentLoginViewController
- and the compiler keeps giving me the error:
no visible @interface for 'NOSbject' declares the selector 'viewDidLoad'
Here's my code:
// StudentLoginViewController.h
#import <UIKit/UIKit.h>
@interface StudentLoginViewController : NSObject <UITextFieldDelegate> {
IBOutlet UILabel *Username ,*Password ;
IBOutlet UIButton *LoginButton ;
IBOutlet UITextField *UsernameText ,*PasswordText;
}
@end
// StudentLoginViewController.m
#import "StudentLoginViewController.h"
@interface StudentLoginViewController ()
@end
@implementation StudentLoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
UsernameText.delegate=self;
PasswordText.delegate=self;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
// this text will not be updated to the newest text yet,
// but we know what what the user just did to get into a string
NSString *Username, *Password;
if (textField == UsernameText) {
Username = @"jzarate";
Password = PasswordText.text;
} else {
Username= UsernameText.text;
Password = @"14054";
}
// If both the username and password are correct then enable the button
LoginButton.enabled = ([Username isEqualToString:@"jzarate"] && [Password isEqualToString:@"14054"]);
// return YES so that the users edits are used
return YES;
}
@end
Please note that the code above for the .m file is all the code in it, I have removed the other bits above and below this.
Upvotes: 0
Views: 228
Reputation: 13546
It is because viewDidLoad
is invoked when you will inherit StudentLoginViewController
from UIViewController
instead of NSObject. NSObject is itself a super Class of all, so it does not have any parent, who declares viewDidLoad. So you are getting error at:
[super viewDidLoad];
Write:
@interface StudentLoginViewController : UIViewController <UITextFieldDelegate>
instead of
@interface StudentLoginViewController : NSObject <UITextFieldDelegate>
Upvotes: 2