在iPhone中访问typedef枚举功能?

时间:2012-08-23 07:21:12

标签: iphone ios5 enums typedef

我正在使用标头中的某些值来定义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;
}

但视图加载后未调用的方法。我怎么能这样做。请帮助我

1 个答案:

答案 0 :(得分: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;


 }