Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 17, 2013, 08:57 AM   #1
kikko088
macrumors member
 
Join Date: Oct 2010
Location: Italy
Edit NSTableView - NSArrayController

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?
__________________
iTouch 1G

Last edited by kikko088; Jan 17, 2013 at 09:08 AM.
kikko088 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 04:53 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC