2012-03-14 5 views
-1

내가 주석 처리 한 코드에서 몇 가지 오류가 있지만 해결 방법을 모릅니다. 너는 내가 그것을 고치기 위해 내가해야 할 일을 한 번 봐 주시겠습니까?식별자 오류 등

TIA

구현 파일

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 
@synthesize textField; 
@synthesize label; 

@synthesize userName = _userName; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)viewDidUnload 
{ 
    [self setTextField:nil]; 
    [self setLabel:nil]; 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

- (IBAction)changeGreeting:(id)sender { 

    self.userName = self.textField.text; 

    NSString *nameString = self.userName; 
    if ([nameString length] == 0) 
     nameString = @"World"; 
    } 
NSString *greeting = [[NSString alloc]initWithFormat:@"Hello, %@!", nameString]; // Use of undeclared identifier 'nameString' 
self.label.text = greeting; // Unknown type 'self' 
} // Expected external declaration 
@end 

인터페이스 파일 :

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController 

@property (weak, nonatomic) IBOutlet UITextField *textField; 
@property (weak, nonatomic) IBOutlet UILabel *label; 

- (IBAction)changeGreeting:(id)sender; 

@property (copy, nonatomic)NSString *userName; 

@end 
+1

힌트 들여다보기. 그리고 이전 줄에서 오류가있는 줄에서 찾을 수없는 오류가 발생하면 잘못된 줄이없는 경우 이전 줄로 다시 이동하십시오. 린스하고 반복하십시오. –

+0

확인을 클릭하여 문제를 찾아 해결합니다. 고맙습니다! – pdenlinger

답변

1

마지막 제 파일 블록 개구 브래킷이없는 경우

... 
- (IBAction)changeGreeting:(id)sender { 

    self.userName = self.textField.text; 

    NSString *nameString = self.userName; 
    if ([nameString length] == 0){ 
        nameString = @"World"; 
    } 
    NSString *greeting = [[NSString alloc]initWithFormat:@"Hello, %@!", nameString]; 
    self.label.text = greeting; 
} 
@end 
+0

감사합니다. 내가 언급 한 것을 잊어 버린 또 하나의 오류 : 구현 파일의 상단에서, @implementation 후에 얻고 있습니다. ViewController '@end가 구현 컨텍스트에서 누락되었습니다.'그게 무슨 뜻입니까? – pdenlinger

+0

이전 오류로 인해 @end가 마지막에 숨어 있었기 때문입니다. if 블록을 수정하여이를 수정해야합니다. – Ben