Objective-C代码中未声明标识符的问题

时间:2015-09-13 22:38:20

标签: ios objective-c undeclared-identifier

我的构建一直在失败。它说我有一些未声明的标识符,但我不确定要声明什么以及如何声明。请帮忙。这是Objective-C。

这是我的ViewController.m viewDidLoad

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



-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    [dateLabel resignFirstResponder]; //the textField that you will set the selected date
    datePicker = [[UIDatePicker alloc] init]; //declared uidatepicker component

    pickerViewDate = [[UIActionSheet alloc] initWithTitle:@"Select the date!"
                                                 delegate:self
                                        cancelButtonTitle:nil
                                   destructiveButtonTitle:nil
                                        otherButtonTitles:nil];

    datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
    datePicker.datePickerMode = UIDatePickerModeDate; //set your spesific mode

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; //or another LocaleIdentifier instead of en_US
    [dateFormatter setDateFormat:@"dd.MM.yyyy"]; //desired format

    [datePicker addTarget:self action:@selector(dateChanged) forControlEvents:UIControlEventValueChanged]; //the function would be fired when user change the date in datePicker

    //now preparing the toolbar which will be displayed at the top of the datePicker
    pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    pickerToolbar.barStyle=UIBarStyleBlackOpaque;
    [pickerToolbar sizeToFit];
    NSMutableArray *barItems = [[NSMutableArray alloc] init];
    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonClicked)]; //barbutton item is "DONE" and doneButtonClicked action will be fired when user clicks the button.
    [barItems addObject:flexSpace]; // set the left of the bar

    [pickerToolbar setItems:barItems animated:YES];
    [pickerViewDate addSubview:pickerToolbar];
    [pickerViewDate addSubview:datePicker];
    [pickerViewDate showInView:self.view];
    [pickerViewDate setBounds:CGRectMake(0,0,320, 464)]; //you can change the position
}
}

-(IBAction)dateChanged{
NSDateFormatter *FormatDate = [[NSDateFormatter alloc] init];
[FormatDate setLocale: [[NSLocale alloc]
                        initWithLocaleIdentifier:@"en_US"]];
[FormatDate setDateFormat:@"dd.MM.yyyy"];
dateLabel.text = [FormatDate stringFromDate:[UIDatePicker date]];
}

-(BOOL)closeDatePicker:(id)sender{
[pickerViewDate dismissWithClickedButtonIndex:0 animated:YES];
[dateLabel resignFirstResponder];
return YES;
}

-(IBAction)doneButtonClicked{
[self closeDatePicker:self];
}

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

- (IBAction)datePicker:(UITextField *)sender {
}
- (IBAction)textFieldDidBeginEditing:(UITextField *)sender {
}
@end

这些是我的声明:

@property (weak, nonatomic) IBOutlet UISegmentedControl *gob;
@property (weak, nonatomic) IBOutlet UITextField *pd;

@property (weak, nonatomic) IBOutlet UIButton *calculate;
@property (weak, nonatomic) IBOutlet UILabel *nd;
@property (weak, nonatomic) IBOutlet UIButton *save;
@property (weak, nonatomic) IBOutlet UILabel *cd;
@property (weak, nonatomic) IBOutlet UIButton *reset;
@property (weak, nonatomic)IBOutlet UIDatePicker *datePicker;
- (IBAction)textFieldDidBeginEditing:(UITextField *)sender;
- (IBAction)datePicker:(UITextField *)sender;
- (IBAction)textFieldDidBeginEditing:(UITextField *)sender;
- (IBAction)dateLabel:(UITextField)sender;
- (IBAction)pickerToolbar:(UIToolbar)sender;

它为textFieldDidBeginEditing',' pickerViewDate'提供了错误。和' dateLabel'。 请帮助我搜索其他问题所以我不只是在没有研究的情况下发帖。

1 个答案:

答案 0 :(得分:0)

viewDidLoad方法中有textFieldDidBeginEditing。它们应该分开。

代码:

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

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    [dateLabel resignFirstResponder]; //the textField that you will set the selected date
    datePicker = [[UIDatePicker alloc] init]; //declared uidatepicker component

    pickerViewDate = [[UIActionSheet alloc] initWithTitle:@"Select the date!"
                                                 delegate:self
                                        cancelButtonTitle:nil
                                   destructiveButtonTitle:nil
                                        otherButtonTitles:nil];

    datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
    datePicker.datePickerMode = UIDatePickerModeDate; //set your spesific mode

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; //or another LocaleIdentifier instead of en_US
    [dateFormatter setDateFormat:@"dd.MM.yyyy"]; //desired format

    [datePicker addTarget:self action:@selector(dateChanged) forControlEvents:UIControlEventValueChanged]; //the function would be fired when user change the date in datePicker

    //now preparing the toolbar which will be displayed at the top of the datePicker
    pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    pickerToolbar.barStyle=UIBarStyleBlackOpaque;
    [pickerToolbar sizeToFit];
    NSMutableArray *barItems = [[NSMutableArray alloc] init];
    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonClicked)]; //barbutton item is "DONE" and doneButtonClicked action will be fired when user clicks the button.
    [barItems addObject:flexSpace]; // set the left of the bar

    [pickerToolbar setItems:barItems animated:YES];
    [pickerViewDate addSubview:pickerToolbar];
    [pickerViewDate addSubview:datePicker];
    [pickerViewDate showInView:self.view];
    [pickerViewDate setBounds:CGRectMake(0,0,320, 464)]; //you can change the position
}