1

pickerView にユーザー入力を入力するテキスト フィールドを設定しようとしています。アプリケーションを起動するたびに、次のエラーが発生します。

NSInvalidArgumentException', reason: '-[UITextField isEqualToString:]: unrecognized   selector sent to instance.

@synthesize pickerView;
@synthesize textArray;
@synthesize textField;

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.textArray = [[NSMutableArray alloc] init];

    PFUser *currentUser = [PFUser currentUser];
    if (currentUser) {
    NSLog(@"Current user: %@" , currentUser.username);
}
else {
    [self performSegueWithIdentifier:@"showLogin" sender:self];
}
    self.textField.delegate = self;

    self.pickerView.dataSource = self;
    self.pickerView.delegate = self;

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

[nc addObserver:self selector:@selector(keyboardWillShow:) name:
 UIKeyboardWillShowNotification object:nil];

[nc addObserver:self selector:@selector(keyboardWillHide:) name:
 UIKeyboardWillHideNotification object:nil];

self.tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                            action:@selector(didTapAnywhere:)];
}

-(void)didTapAnywhere: (UITapGestureRecognizer *) note {
    [self.textField resignFirstResponder];
}
-(void) keyboardWillShow:(NSNotification *) note {
    [self.view addGestureRecognizer:self.tapRecognizer];
}

-(void) keyboardWillHide:(NSNotification *) note
{
    [self.view removeGestureRecognizer:self.tapRecognizer];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:   (NSInteger)component
{
    if ([self.textArray count] == 0)
        return 1;
    return [self.textArray count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:   (NSInteger)component {
    return [self.textArray objectAtIndex:row];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row forComponent:    (NSInteger)component{
    NSLog(@"You selected this: %@", [self.textArray objectAtIndex:row]);
}

-(void)textFieldDidEndEditing:(UITextField *)textField{

    [self.textArray addObject:self.textField.text];

    [self.textField resignFirstResponder];

}

- (IBAction)logout:(id)sender {
    [PFUser logOut];
    [self performSegueWithIdentifier:@"showLogin" sender:self];
}
@end

私はすべてに慣れていないので、おそらくそれが基本的なものであれば、気楽に行ってください。乾杯!

4

2 に答える 2