简体   繁体   中英

Set selected row in UIPickerView from Parse objects

In a view there is a text field and a picker view. The picker view items are loaded from a Parse query. The text field text is always one of the picker view items. The picker view selected item must be the same as the text field text. That is my code for the moment, but it throws an exception:

PFQuery *query = [PFQuery queryWithClassName:@"floors"];
[query whereKey:@"floor_restaurant" equalTo:self.restaurante.objectId];
[query orderByDescending:@"createdAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

if (!error) { _pickerData = objects;

    for (int i = 0; i < [objects count]; i++)
    {
        if ([[objects objectAtIndex:i] isEqualToString: self.floor_name_text.text]){
            [self.floor_picker selectRow:i inComponent:0 animated:YES];

            break;
        }

    }

    [self.floor_picker reloadAllComponents];



}
else {
    NSLog(@"error");
}

}];

That is the exception:

2015-02-28 21:03:20.707 RestAppXXI[675:60b] -[PFObject isEqualToString:]: unrecognized selector sent to instance

I am new to Parse with iOS and any help is welcome.

EDITED :

- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    PFObject *object = _pickerData[row];

        return object[@"floor_name"];


}

Thanks to the comments of rmaddy and a little searching, I have resolved my issue, here is the final code that works:

[PFQuery *query = [PFQuery queryWithClassName:@"floors"];
    [query whereKey:@"floor_restaurant" equalTo:self.restaurante.objectId];
    [query orderByDescending:@"createdAt"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            _pickerData = objects;


            for (int i = 0; i < [objects count]; i++)
            {
                NSString *textoactual = self.floor_name_text.text;


                if ([[[objects  objectAtIndex:i] objectForKey:@"floor_name" ] isEqualToString: textoactual]){

                    [self.floor_picker reloadAllComponents];
                    [self.floor_picker selectRow:i inComponent:0 animated:YES];

                    break;
                }

            }





        }
        else {
            NSLog(@"error");
        }
    }];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM