這裏是我TextValidator類:iOS的錯誤:「XXXX」無可見@interface聲明選擇「頁頭」
//TextValidator.h
#import <Foundation/Foundation.h>
@interface TextValidator : NSObject
- (BOOL) isValidPassword:(NSString *)checkPassword;
- (BOOL) isValidEmail:(NSString *)checkString;
- (BOOL) isEmpty:(NSString *)checkString;
@end
// TextValidator.m
#import "TextValidator.h"
@implementation TextValidator
- (BOOL) isEmpty:(NSString *)checkString
{
return YES;
}
- (BOOL) isValidPassword:(NSString *)checkPassword
{
return YES;
}
- (BOOL) isValidEmail:(NSString *)checkString
{
return YES;
}
@end
這是我嘗試初始化在ViewController.m的TextValidator類方式:
//ViewController.h
#import <Foundation/Foundation.h>
@interface SignUpViewController : UIViewController <UITextFieldDelegate>
@end
//ViewController.m
#import "SignUpViewController.h"
#import "TextValidator.h"
@interface SignUpViewController()
@property TextValidator *myValidator;
@end
@implementation SignUpViewController
- (void)viewDidLoad
{
[[self.myValidator alloc] init]; //iOS error: No visible @interface for 'TextValidator' declares the selector 'alloc'*
[super viewDidLoad];
}
@end
當我嘗試編譯代碼我收到以下錯誤:
No visible @interface for 'TextValidator' declares the selector 'alloc'.
TextValidator類和poorly從NSObject和據我所知init和alloc函數已經在基類中定義。那麼爲什麼程序會出現這樣的錯誤呢?
請注意,我已經檢查this主題,它不適用於我。
正確加1 –