有一个员工列表有一个应用程序,每个员工可以有几个任务。单击员工时,他的任务将打开。此处应用程序开始无法正常工作,即打开所有任务,而不仅仅是针对特定员工。
数据库方案:https://drive.google.com/open?id=0BxSMtqa62EX9TGE5eVlwX1BoaU0
项目:https://drive.google.com/open?id=0BxSMtqa62EX9RVIzcWtCaktpM0E
点击处理:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"empToTasks"]){
NSManagedObject *selectedDevice = [self.employees objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
TasksViewController *destViewController = segue.destinationViewController;
destViewController.emp = selectedDevice;
}
}
添加任务:
- (IBAction)saveTask:(id)sender{
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *newTask = [NSEntityDescription insertNewObjectForEntityForName:@"Tasks" inManagedObjectContext:context];
[newTask setValue:self.tasksField.text forKey:@"task"];
[newTask setValue:self.dataTasksField.text forKey:@"dateTask"];
NSError *error=nil;
if (![context save:&error]) {
NSLog(@"Can't save %@ %@", error, [error localizedDescription] );
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Ура" message:@"Успешно добавлено" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
}
}
查看表中的任务:
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:`(NSInteger)section{
return self.emp.task.count;
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell1";
UITableViewCell*cell1 =[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Tasks *currentTask =[self.emp.task.allObjects objectAtIndex:indexPath.row];
cell1.textLabel.text = currentTask.task;
return cell1;
}
仅显示特定员工的任务需要更正什么?
最佳答案
我认为问题在于您在保存/添加任务数据时没有引用特定的 employee
。并获取整张 table 。您应该添加第三个键作为引用,并在提取到 TasksViewController
的 ViewDidLoad
时在该引用上添加谓词。获得特定的员工任务。
希望我没听错。
关于ios - iOS、Core Data应用中的错误通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36236301/