Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kikko088

macrumors member
Original poster
Oct 13, 2010
77
0
Italy
Hi at all I have some problem tryng to editing value inside nstableview, I binding the table with an nsarraycontroller, for add and editing a value I use this methods:

Code:
- (IBAction) addNewMateria:(id)sender{
        
        isNew = YES;
        
        Materia *newMat = [[Materia alloc] init];
        
        [self.arrayMaterieController addObject:newMat];
}
- (void) editingDidEnd:(NSNotification *)notification {
        
             NSTableView *table = [notification object];
                
             Materia *newMat = [[Materia alloc] init];
                
             if([table selectedRow] != -1) {
                 NSArray *selectedObjects = [self.arrayMaterieController selectedObjects];
                 newMat = [selectedObjects objectAtIndex:0];
             }
        
             if (isNew == YES) {
                
                 if (newMat.idMateria != nil && newMat.titoloMateria!= nil && newMat.iconaMateria!= nil){
                  
                     NSString *strQuery = [NSString stringWithFormat:@"INSERT INTO Materie (IDMateria, TitoloMateria, IconaMateria) VALUES ('%@', '%@', '%@')",
                                              newMat.idMateria,newMat.titoloMateria,newMat.iconaMateria];
                     [dataLoad  update:strQuery];
                    
                     isNew = NO;
                 }
             }
             else {
                 NSString *strQuery = [NSString stringWithFormat:@"UPDATE Materie SET IDMateria='%@', TitoloMateria='%@' ,IconaMateria='%@' WHERE IDMateria='%@'",
                                       newMat.idMateria,newMat.titoloMateria,newMat.iconaMateria,self.materiaOld.idMateria];
                 [dataLoad  update:strQuery];
       }
}

- (void) controlTextDidBeginEditing:(NSNotification *)aNotification {
        
        if ([[aNotification object] isKindOfClass:[NSTableView class]]) {
            
            NSLog(@"Tabella strt editing");
            
            NSTableView *aTableView = [aNotification object];
            
            if (aTableView == tabellaMateria) {
                self.materiaOld = [self.arrayMaterie objectAtIndex:[aTableView selectedRow]];
            }
        }
}
my problem is that when I edit a value the object oldMaterie change with new object, so I can't update the value on my database because I can't store the old id of object, where is the mistake?
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.