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

Similar Threads
thread Thread Starter Forum Replies Last Post
NSTableView get selected row data cpuin Mac Programming 2 Oct 2, 2013 11:08 AM
Text edit can't edit Html pages phobos OS X 5 Mar 27, 2013 12:43 PM
Call reloadData for NSTableView from AppDelegate AdrianK Mac Programming 3 Aug 11, 2012 01:32 PM
Reordering rows in a view-based NSTableVIew monsieurpaul Mac Programming 2 Jul 19, 2012 08:21 AM
Asynchronous NSURLConnections + NSTableView Help jwei92 Mac Programming 0 Jul 10, 2012 08:42 PM

Forum Jump

All times are GMT -5. The time now is 03:23 PM.

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

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