有一個應用程序有一個工作人員名單和一份說明列表。並且,當您在TextField中創建訂單時,PickerView應該與員工名單(帶名稱)一起出現。如何從PickerView中的核心數據中獲取數據? iOS
- (void)viewDidLoad {
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Employees"];
self.empl=[[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
UIPickerView *picker = [[UIPickerView alloc]init];
picker.dataSource = self;
picker.delegate = self;
[picker setShowsSelectionIndicator:YES];
[self.empTaskField setInputView:picker];
}
#pragma mark - UIPickerView DataSource Method
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return self->_empl.count;
}
#pragma mark - UIPickerView Delegate Method
-(NSString *) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [_empl objectAtIndex:row];
}
當你點擊文本字段出現錯誤:
27/03/2016 23 : 32 : 57.177 Employee Task [ 2730 : 150090 ] - [Employees copyWithZone:]: unrecognized selector sent to instance 0x7fcf2ac84fd0 2016-03-27 23 : 32 : 57.513 Employee Task [ 2730 : 150090 ] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [Employees copyWithZone:]: unrecognized selector sent to instance 0x7fcf2ac84fd0'
如何解決這個問題,我將實現如下呢?
你的問題是這一行:'self.empl = [[managedObjectContext executeFetchRequest:fetchRequest錯誤:零] mutableCopy]''Employees'沒有實現'NSCopying'協議。 – Larme