J'ai un tableviewController avec des cellules personnalisées qui contiennent une étiquette et un commutateur. i enregistrer l'état du commutateur dans CoreDataEnregistrement USSwitch à CoreData
- (IBAction)roomSwitch:(id)sender {
NSLog(@"Switch wurde betätigt");
NSManagedObjectContext *context = [app managedObjectContext];
UISwitch *switcher = sender;
NSInteger rowInIndexPath = switcher.tag;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowInIndexPath inSection:0];
Raumattribute *att=[self.fetchedResultsController objectAtIndexPath:indexPath];
att.switch = [NSNumber numberWithBool:switcher.on];
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
NSLog(@"Schalter: %@", att.switch);
}
This Works ->
2012-03-28 16:43:34.657 Book-App[40011:11903] Switch: 1
2012-03-28 16:43:37.373 Book-App[40011:11903] Switch wurde betätigt
2012-03-28 16:43:37.377 Book-App[40011:11903] Switch: 0
Dans mon cellForRowAtIndexPath j'ai [cell.raumSwitch addTarget:self action:@selector(roomSwitch:) forControlEvents:UIControlEventValueChanged];
Wich appelle le roomSwitch:
Maintenant, mon problème est que si je change un commutateur, un autre commutateur va également changer son état. Comment puis-je dire au Switch à quel rang il appartient.
Mon deuxième problème est que si je change d'affichage, tous les commutateurs sont désactivés. Comment puis-je montrer l'état actuel qui est enregistré dans CoreData?
J'ai essayé
cell.roomSwitch = [managedObject valueForKey:@"switch"];
mais il se bloque.
J'espère que quelqu'un comprendra mes problèmes.
J'ai trouvé la solution par moi même mySwitch.on = [[managedObject valueForKey: @ "schalter"] boolValue]; THX pour votre aide! – Bashud