Опитвам се да запазя някои данни в CoreData, но получавам грешката:
Restaurant Manager[5971:60b] * Прекратяване на приложението поради неуловено изключение „NSInvalidArgumentException“, причина: „-[ProdusComandat setIdProdus:]: неразпознат селектор, изпратен до екземпляр 0x90b8270“
Може ли някой да ми каже защо?
SessionController* sessionController = [[SessionController alloc]init];
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"ComenziActive"];// baza de date
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"numeClient == %@",sessionController.getSessionUsername]];
NSError *err;
NSUInteger count = [self.managedObjectContext countForFetchRequest:fetchRequest error:&err];
NSArray *listaElementeBD = [[NSArray alloc]init];
if(count <= 0)
{
NSEntityDescription *entitydesc;
entitydesc = [NSEntityDescription entityForName:@"ComenziActive" inManagedObjectContext:self.managedObjectContext];
ComenziActive *comanda = [NSEntityDescription insertNewObjectForEntityForName:@"ComenziActive" inManagedObjectContext:self.managedObjectContext];
[comanda setValue:sessionController.getSessionUsername forKey:@"numeClient"];
ProdusComandat * produsComandat = [[ProdusComandat alloc]init];
produsComandat.idProdus = [[[(Produs*)produsdb objectID] URIRepresentation] absoluteString];
produsComandat.cantitateComandata = [NSNumber numberWithInteger:[self.cantitateTextField.text integerValue]];
[comanda addProduseComandateObject:produsComandat];
}
else
{
NSError *error;
listaElementeBD = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
ComenziActive *comanda = [listaElementeBD objectAtIndex: 0];
NSArray *produse = comanda.produseComandate.allObjects;
BOOL found =NO;
for(int i=0;i<[produse count];i++)
{
ProdusComandat *p =[[ProdusComandat alloc]init];
p= produse[i];
if ([p.idProdus isEqualToString:[[[(Produs*)produsdb objectID] URIRepresentation] absoluteString]]) {
p.cantitateComandata = [NSNumber numberWithInteger:[p.cantitateComandata integerValue] + [self.cantitateTextField.text integerValue]];
found = YES;
break;
}
}
if (!found) {
ProdusComandat * produsComandat = [[ProdusComandat alloc]init];
produsComandat.idProdus = [[[(Produs*)produsdb objectID] URIRepresentation] absoluteString];
produsComandat.cantitateComandata = [NSNumber numberWithInteger:[self.cantitateTextField.text integerValue]];
[comanda addProduseComandateObject:produsComandat];
}
NSLog(@"============================");
NSLog(@"%@", comanda.produseComandate );
}
NSError *error;
[self.managedObjectContext save:&error];
Това, което се опитвам да направя, е да получа данните от CoreData обект Produs и да копирам неговия objectID в обекта ProduseComandate който има тази връзка ComenziActive‹----->>ProduseComandate(релация едно към много), ако този objectID не съществува в таблицата, но ако съществува, искам да добавя към стойността cantiate някаква стойност, която вземам от TextField.
idProdus
? - person Wain   schedule 04.05.2014