How do I edit a row in NSTableView to allow deleting the data in that row and replacing with new d

Posted by lampShade on Stack Overflow See other posts from Stack Overflow or by lampShade
Published on 2010-05-05T01:06:27Z Indexed on 2010/05/05 1:38 UTC
Read the original article Hit count: 330

Filed under:
|
|

I'm building a to-do-list application and I want to be able to edit the entries in the table and replace them with new entries. I'm close to being able to do what I want but not quit. Here is my code so far:

/*
 IBOutlet NSTextField *textField;
 IBOutlet NSTabView *tableView;
 IBOutlet NSButton *button;
 NSMutableArray *myArray;
 */

#import "AppController.h"


@implementation AppController


-(IBAction)addNewItem:(id)sender
{

    [myArray addObject:[textField stringValue]];
    [tableView reloadData];     
}

- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
    return [myArray count];
}

- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
            row:(int)rowIndex
{

    return [myArray objectAtIndex:rowIndex];
}

- (id)init
{
    [super init];
    myArray = [[NSMutableArray alloc] init];
    return self;
}
-(IBAction)removeItem:(id)sender
{

    NSLog(@"This is the index of the selected row: %d",[tableView selectedRow]);
    NSLog(@"the clicked row is %d",[tableView clickedRow]);
    [myArray replaceObjectAtIndex:[tableView selectedRow] withObject:[textField stringValue]];
    [myArray addObject:[textField stringValue]];
    //[tableView reloadData];
}

@end

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about beginner