objective c - The wrong communications in application of iOS, Core Data -


there application list of employees has, , each employee can have several tasks. when clicking employee tasks shall open. here application begins work not correctly, namely opens tasks, , not specific employee.

database scheme: https://drive.google.com/open?id=0bxsmtqa62ex9tge5evlwx1boau0

project: https://drive.google.com/open?id=0bxsmtqa62ex9rvizcwtcaktpm0e

clicking processing:

-(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;                 }     } 

add task:

 - (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];         }     } 

view task in table:

-(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;     } 

what needs corrected tasks of specific employee shown?

i think problem saving/ adding task data without reference perticular employee . , fetching whole table . should add 3rd key reference , add predicate on reference while fetching viewdidload of tasksviewcontroller . perticular employee task .

hope got correctly .


Comments