在视图中,有一个文本字段和一个选择器视图。选取器视图项是从Parse查询加载的。 文本字段文本始终是选取器视图项之一。 选择器视图选定项必须与文本字段文本相同。这是我目前的代码,但它抛出异常:
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");
}
}];
这是例外:
2015-02-28 21:03:20.707 RestAppXXI[675:60b] -[PFObject isEqualToString:]: unrecognized selector sent to instance
我是iOS的Parse新手,欢迎任何帮助。
已编辑:
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
PFObject *object = _pickerData[row];
return object[@"floor_name"];
}
答案 0 :(得分:1)
感谢rmaddy的评论和一些搜索,我已经解决了我的问题,这是最终的代码:
[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");
}
}];