2015-03-02 78 views
0

我是新來的編碼,並有一些基本的知識,但我構建了我的第一個應用程序從一個教程,並有一個問題,我無法弄清楚,經過幾天的尋找我想只會問。初始化視圖中的對象時,我的實現文件中出現錯誤。它說使用未聲明的標識符。任何幫助將不勝感激。Xcode使用未聲明的標識符

這是我的看法Controller.m或者

#import "ViewController.h" 





@implementation ViewController 




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

    NSLog(@"titleLabel.text = %@", self.titleLabel.text); 

    self.bandObject = [[BandObject alloc] init]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
    return YES; 
} 

-(BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
    self.bandObject.name = self.nameTextField.text; 
    [self.nameTextField resignFirstResponder]; 
    return YES; 
} 

-(BOOL)textFieldShouldEndEditing:(UITextField *)textField 
{ 
    self.bandObject.name =self.nameTextField.text; 
    [self saveBandObject]; 
    [self.nameTextField resignFirstResponder]; 
    return YES; 
} 

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView 
{ 
    self.saveNotesButton.enabled = YES; 
    return YES; 
} 

-(BOOL)textViewShouldEndEditing:(UITextView *)textView 
{ 
    self.bandObject.notes = self.notesTextView.text; 
    [self.notesTextView resignFirstResponder]; 
    self.saveNotesButton.enabled = NO; 
    return YES; 
} 

- (IBAction)saveNotesButtonTouched:(id)sender 
{ 
    [self textViewShouldEndEditing:self.notesTextView]; 
} 

- (IBAction)ratingStepperValueChanged:(id)sender 
{ 
    self.ratingValueLabel.text = [NSString stringWithFormat:@"%g",self.ratingStepper.value]; 
    self.bandObject.rating = (int)self.ratingStepper.value; 
} 


- (IBAction)tourStatusSegmentedControlValueChanged:(id)sender 
{ 
    self.bandObject.touringStatus = self.touringStatusSegmentedControl.selectedSegmentIndex; 
} 

- (IBAction)haveSeenLiveSwitchValueChanged:(id)sender 
{ 
    self.bandObject.haveSeenLive = self.haveSeenLiveSwitch.on; 
} 

@end 

這裏是我的.h

#import <UIKit/UIKit.h> 
#import "WBABand.h" 


@interface ViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate> 

@property (nonatomic, strong) WBABand *bandObject; 
@property (nonatomic, weak) IBOutlet UILabel *titleLabel; 
@property (nonatomic, weak) IBOutlet UITextField *nameTextField; 
@property (nonatomic, weak) IBOutlet UITextView *notesTextView; 
@property (nonatomic, weak) IBOutlet UIButton *saveNotesButton; 
@property (nonatomic, weak) IBOutlet UIStepper *ratingStepper; 
@property (nonatomic, weak) IBOutlet UILabel *ratingValueLabel; 
@property (nonatomic, weak) IBOutlet UISegmentedControl *touringStatusSegmentedControl; 
@property (nonatomic, weak) IBOutlet UISwitch *haveSeenLiveSwitch; 

- (IBAction)saveNotesButtonTouched:(id)sender; 
- (IBAction)ratingStepperValueChanged:(id)sender; 
- (IBAction)tourStatusSegmentedControlValueChanged:(id)sender; 
- (IBAction)haveSeenLiveSwitchValueChanged:(id)sender; 



@end 

回答

0

當你遇到問題,請嘗試將它縮小到最短的代碼塊可能重現。至少,你應該指出顯示錯誤的那一行,以便貢獻者可以幫助你更輕鬆。


您正在嘗試實例化的BandObject的實例,但你應該嘗試實例化的類是WBABand

self.bandObject = [[WBABand alloc] init]; 
2

這是因爲你的.h中有一個對象叫做WBABand。而在你的.m你正在初始化一個不存在的BandObject

更改此[[BandObject alloc] init];

這個[[WBABand alloc] init];