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