1

我正在使用标头中的一些值来 typedef。我如何访问枚举值并在应用程序中使用任何人帮助我。

typedef enum{
INFO,PROD,WARN
}INFOS;
@interface ViewController : UIViewController{
     INFOS infos;
}
-(NSString *)method:(INFOS)infovalue;
- (void)viewDidLoad
{

 [self method:infos];

[super viewDidLoad];
}
- (NSString *) method:(INFOS) infovalue {
NSString *result = nil;

switch(infovalue) {
    case INFO:
        result = @"info";
        break;
    case PROD:
        result = @"prod";
        break;
    case WARN:
        result = @"warn";
        break;

    default:
        result = @"unknown";
}

return result;
}

但视图加载后未调用该方法。我该怎么做。请帮帮我

4

1 回答 1

1
typedef enum{
   info = 1,
   prod = 2,
   warn = 3
}INFOS;

@interface ViewController : UIViewController{
     //INFOS infos; you do not need this
}
-(NSString *)method:(INFOS)infovalue;
-(void)viewDidLoad;
{

 [self method:info];

 [super viewDidLoad];
}
- (NSString *) method:(INFOS) infovalue {
NSString *result = nil;

switch(infovalue) {
    case 1:
        result = @"info";
        break;
    case 2:
        result = @"prod";
        break;
    case 3:
        result = @"warn";
        break;

    default:
        result = @"unknown";
}

return result;


 }
于 2012-08-23T07:27:06.170 回答