2013-03-28 71 views
0

我已經輸入到這一點我.m文件 - StudentLoginViewController - 和編譯器不斷給我的錯誤:缺少方法聲明

no visible @interface for 'NOSbject' declares the selector 'viewDidLoad'

這裏是我的代碼:

// 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 

請注意上面的.m文件的代碼是其中的所有代碼,我已經刪除了上面和下面的其他位。

+0

這有**絕對*不***做:

[super viewDidLoad];

寫:那麼,你是在得到錯誤Xcode也不用'if語句。 – 2013-03-28 07:10:31

+0

是什麼促使你爲超類選擇「NSObject」? – 2013-03-28 07:11:44

+0

我沒有提示它,它自己做了,當我去玩它的IOS IPhone6.1發電機 – 2013-03-28 07:16:54

回答

2

這是因爲viewDidLoad被調用時,將從UIViewController而不是NSObject繼承StudentLoginViewController。 NSObject本身就是一個超類,所以它沒有任何聲明viewDidLoad的父類。的

@interface StudentLoginViewController : UIViewController <UITextFieldDelegate>

代替

@interface StudentLoginViewController : NSObject <UITextFieldDelegate>

+0

所以我該怎麼辦? – 2013-03-28 07:17:22

+0

看到我的編輯。希望你能理解。 – NightFury 2013-03-28 07:21:36

+0

@AnumAmin誰說你不能在NSObject上使用IBOutlets?進入IB並搜索NSObject,然後拖入其中並親自查看。 – CodaFi 2013-03-28 07:31:45