我正在使用标头中的某些值来定义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;
}
但视图加载后未调用的方法。我怎么能这样做。请帮助我
答案 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;
}