Objective c 未声明标识符的使用

Objective c 未声明标识符的使用,objective-c,ios,xcode,Objective C,Ios,Xcode,我正在尝试配置一个双组件选择器,但遇到一些错误,我已将其注释掉: 实施文件: #import "BIDDoubleComponentPickerViewController.h" @implementation BIDDoubleComponentPickerViewController @synthesize doublePicker; @synthesize fillingTypes; @synthesize breadTypes; - (IBAction)buttonPressed:

我正在尝试配置一个双组件选择器,但遇到一些错误,我已将其注释掉:

实施文件:

#import "BIDDoubleComponentPickerViewController.h"

@implementation BIDDoubleComponentPickerViewController

@synthesize doublePicker;
@synthesize fillingTypes;
@synthesize breadTypes;

- (IBAction)buttonPressed:(id)sender
{
    NSInteger fillingRow =  [doublePicker selectedRowInComponent:kFillingComponent]; // Use of undeclared identifier 'kFillingComponent'
    NSInteger breadRow = [doublePicker selectedRowInComponent:kBreadComponent]; // Use of undeclared identifier 'kBreadComponent'

    NSString *bread = [breadTypes objectAtIndex:breadRow];
    NSString *filling = [fillingTypes objectAtIndex:fillingRow];

    NSString *message = [[NSString alloc]initWithFormat:@"Your %@ on %@ bread 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];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSArray *fillingArray = [[NSArray alloc] initWithObjects:@"Ham", @"Turkey", @"Peanut Butter", @"Tuna Salad", @"Chicken Salad", @"Roast Beef", @"Vegemite", nil];
    self.fillingTypes = fillingArray;

    NSArray *breadArray  = [[NSArray alloc] initWithObjects:@"White", @"Whole Wheat", @"Rye", @"Sourdough Bread", @"Seven Grain", nil];
    self.breadTypes = breadArray;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.doublePicker = nil;
    self.breadTypes = nil;
    self.fillingTypes = nil;
}




#pragma mark - View lifecycle


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#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 identifier 'kBreadComponent'
        return [self.breadTypes.count]; // Expected identifier
        return [self.fillingTypes objectAtIndex:row]; // Use of undeclared identifier 'row'
    }
}

#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{
    if (component == kBreadComponent) { // Use of undeclared identifier 'kBreadComponent'
        return [self.breadTypes objectAtIndex:row];
        return [self.fillingTypes objectAtIndex:row];
    }
}




@end
接口文件:

#import <UIKit/UIKit.h>

@interface BIDDoubleComponentPickerViewController : UIViewController
<UIPickerViewDelegate, UIPickerViewDataSource>

@property (strong, nonatomic) IBOutlet UIPickerView *doublePicker;
@property (strong, nonatomic) NSArray *fillingTypes;
@property (strong, nonatomic) NSArray *breadTypes;

- (IBAction)buttonPressed:(id)sender;


@end
#导入
@接口BIDDoubleComponentPickerViewController:UIViewController
@属性(强,非原子)IBUIPickerView*双选择器;
@属性(强,非原子)NSArray*填充类型;
@属性(强、非原子)NSArray*宽度类型;
-(iAction)按钮按下:(id)发送者;
@结束

kBreadComponent
kFillingComponent
未在任何地方声明。如果它们是在头文件(.h)中声明的,您需要导入它。

您的
numberOfRowsInComponent
titleForRow
方法类似,它们是错误的:它们有两个无条件的
返回
,这意味着第二个方法永远不会执行

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
{
    return self.breadTypes.count;
}

#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{
    if (component == kBreadComponent) {
    return [self.fillingTypes objectAtIndex:row];
}
    return nil; // Or something, empty string for example. Method requires to return a NSString, so you have to return at least nil;
}

您仍然需要找到
kBreadComponent
kFillingComponent
#导入带有它们定义的文件。

谢谢。在.h文件中遗漏了这一点;添加了它,它成功了。是的,谢谢。发现我复制了一种方法的主体两次。一旦我改变了,我就没事了。