사용

2011-12-01 3 views
4

암은 두 개의 구성 요소 선택기를 구성하려고 내가 주석 몇몇 오류가 점점 오전 :사용

실행 파일 :

#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 

답변

6

kBreadComponentkFillingComponent은 어디에도 선언되어 있지 않습니다. 헤더 (.h) 파일에 선언 된 경우 #import이 필요합니다.

+0

감사합니다. .h 파일에서 그 것을 놓쳤습니다. 그것을 추가하고 그것을 효과. – pdenlinger

0

numberOfRowsInComponenttitleForRow 방법은 비슷하며 잘못되었습니다. 결과적으로 두 가지 결과가 무조건 return 인 두 번째 결과는 절대 실행되지 않습니다.

- (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; 
} 

아직도 당신은 kBreadComponentkFillingComponent#import 이들의 정의를 사용하여 파일을 찾을 수있다.

+0

예, 감사합니다. 내가 한 가지 방법의 몸을 두 번 복사했음을 알았습니다. 일단 내가 바꿨다면, 나는 괜찮 았어. – pdenlinger