我在头文件中声明的常量的实现文件(已注释掉)中收到错误消息。为什么编译器会这样做?
提前致谢。
头文件:
#import <UIKit/UIKit.h>
#define kFilling Component 0
#define kBread Component 1
@interface BIDDoubleComponentViewController : UIViewController
<UIPickerViewDelegate, UIPickerViewDataSource>
@property (strong, nonatomic) IBOutlet UIPickerView *doublePicker;
@property (strong, nonatomic) NSArray *fillingTypes;
@property (strong, nonatomic) NSArray *breadTypes;
- (IBAction) buttonPressed;
@end
实现文件:
#import "BIDDoubleComponentViewController.h"
@implementation BIDDoubleComponentViewController
- (IBAction)buttonPressed
{
NSInteger fillingRow = [self.doublePicker selectedRowInComponent:kFillingComponent]; // Use of undeclared identifieer 'kFillingComponent'
NSInteger breadRow = [self.doublePicker selectedRowInComponent:kBreadComponent]; // Use of undeclared identifieer 'kBreadComponent'
NSString *filling = self.fillingTypes[fillingRow];
NSString *bread = self.breadTypes[breadRow];
NSString *message = [[NSString alloc] initWithFormat:@"Your %@ on %@ will be right up.", filling, bread];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Thank you for your order"
message:message
delegate:nil
cancelButtonTitle:@"Great"
otherButtonTitles:nil];
[alert show];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.fillingTypes = @[@"Ham", @"Turkey", @"Peanut Butter", @"Tuna salad", @"Chicken salad", @"Roast Beef", @"Vegemite"];
self.breadTypes = @[@"White", @"Whole Wheat", @"Rye", @"Sour Dough", @"Seven-Grain"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if(component == kBreadComponent) // Use of undeclared identifieer 'kFillingComponent'
{
return [self.breadTypes count];
} else {
return [self.fillingTypes count];
}
}
#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if(component == kBreadComponent) // Use of undeclared identifieer 'kBreadComponent'
{
return self.breadTypes[row];
} else {
return self.fillingTypes[row];
}
}
@end