我遇到了如何通过didSelectRow PickerView传递托管对象数据的问题。
调试输出发送回“由于未捕获的异常导致应用终止'NSInvalidArgumentException',原因:' - [Cars isEqualToString:]:无法识别的选择器发送到实例”
我能够成功将相同的数据拉入另一个ViewControler中的表视图中。将它传递给UIPickerView有什么不同?
作为第一个计时器,似乎没有很多资源涉及拣货员和核心数据。 任何帮助将不胜感激。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// New Grab Data From CoreData Store and populate PlateNumbers Array
AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
_managedObjectContext = [appDelegate managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *cars = [NSEntityDescription entityForName:@"Cars" inManagedObjectContext:_managedObjectContext];
[request setEntity:cars];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"created" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[_managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {
// Handled Error
}
[self setPickerPlateNumbers:mutableFetchResults];
NSLog(@"There are a %u in the car array", [self.pickerPlateNumbers count]);
[self.ParkZonePicker reloadAllComponents];
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [self.pickerPlateNumbers count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [self.pickerPlateNumbers objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSString *resultString = [[NSString alloc] initWithFormat: @"Car: %@", [self.pickerPlateNumbers objectAtIndex:row]];
parkCarLabel.text = resultString;
}
**更新**
通过从pickerPlateNumbers数组中寻找的coredata实体传递属性来解决它。
request.resultType = NSDictionaryResultType; request.propertiesToFetch = [NSArray arrayWithObject:[[cars attributesByName] objectForKey:@“numbers”]];