我正在尝试设置一个文本字段,用用户输入填充 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
我对一切都很陌生,所以如果它可能是基本的东西,请放轻松。干杯!