Xcode使用未声明的标识符

时间:2015-03-02 22:03:52

标签: ios xcode identifier

我是编码的新手,并且有一些基本的知识,但我正在构建我的第一个应用程序从一个教程,并有一个问题,我无法弄清楚,并在看了几天看起来我想问。初始化视图中的对象时,我的实现文件中出现错误。 它说使用未声明的标识符。任何帮助将不胜感激。

这是我的视图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

2 个答案:

答案 0 :(得分:2)

这是因为你的.h中有一个名为WBABand的对象。在你的.m中,你正在初始化一个不存在的BandObject

更改此[[BandObject alloc] init];

到此[[WBABand alloc] init];

答案 1 :(得分:0)

当您遇到问题时,请尝试将其缩小到可以重现的最短代码块。至少,您应该指出显示错误的行,以便贡献者可以帮助您更轻松。


您正在尝试实例化BandObject的实例,但您应该尝试实例化的类是WBABand

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