2012-12-12 5 views
0

Apple 설명서에서 복사 한 경우에도 오류 (주석이 있음)를 반환하는이 메서드로 문제가 있습니다.잘못된 형식의 'NSString'단항 ​​식

무엇이 잘못되었는지 말해 줄 수 있습니까?

미리 감사드립니다.

#import "BIDDependentComponentViewController.h" 


@implementation BIDDependentComponentViewController 

- (IBAction)buttonPressed 
{ 
    NSInteger stateRow = [self.dependentPicker selectedRowInComponent:kStateComponent]; 
    NSInteger zipRow = [self.dependentPicker selectedRowInComponent:kZipComponent]; 

    NSString *state = self.states[stateRow]; 
    NSString *zip = self.zips[zipRow]; 

    NSString *title = [[NSString alloc] initWithFormat:@"You selected zip code %@", zip]; 
    NSString *message = [[NSString alloc] initWithFormat:@"%@ is in %@", zip, state]; 

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:title 
                message:message 
                delegate:nil 
             cancelButtonTitle:@"OK" 
             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. 
    NSBundle *bundle = [NSBundle mainBundle]; 
    NSURL *plistURL = [bundle URLForResource:@"statedictionary" withExtension:@"plist"]; 

    self.stateZips = [NSDictionary dictionaryWithContentsOfURL:plistURL]; 
    NSArray *allStates = [self.stateZips allKeys]; 
    NSArray *sortedStates = [allStates sortedArrayUsingSelector:@selector(compare:)]; 
    self.states = sortedStates; 

    NSString *selectedState = self.states[0]; 
    self.zips = self.stateZips[selectedState]; 
} 

- (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 == kStateComponent) 
    { 
     return[self.states count]; 
    } else { 
     return[self.zips count]; 
    } 
} 

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{ 
    if(component == kStateComponent) 
    { 
     NSString *selectedState = self.states[row]; 
     self.zips = self.stateZips[selectedState]; 
     [self.dependentPicker reloadComponent:kZipComponent]; 
     [self.dependentPicker selectRow:0 inComponent:kZipComponent animated:YES]; 
    } 



#pragma mark Picker Delegate Methods 

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component //Invalid argument type 'NSString' to unary expression 
{ 
    if(component == kStateComponent) 
    { 
     return self.states[row]; 
    } else { 
     return self.states[row]; 
    } 
} 

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{ 
    if(component == kStateComponent) 
    {NSString *selectedState = self.states[row]; 
    self.zips = self.stateZips[selectedState]; 
    [self dependentPicker selectRow:0 
    inComponent:kZipComponent 
    animated:YES]; 
} 

@end // Missing @end 

답변

1

이 방법에 닫는 중괄호 }을 놓치고 :

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 

당신의 오류를 모두 해결됩니다 (단 #pragma mark Picker Delegate Methods 위) 올바른 자리에 그 중괄호 퍼팅.

+0

고쳐주었습니다. 고맙습니다. – pdenlinger