Hello,
I'm currently going through the Aaron Hillegass book, and I am doing the challenge at the end of Chapter 6. The challenge is to create a program with 3 controls (NSTextField for input, NSTableView for display, and an NSButton to add what's in the NSTextField to the NSTableView. The program is supposed to be a 'To Do List').
How do I attach/connect my array to the NSTableView? I am interested in doing this via Outlets (not through binding).
Here is the code I have so far. Everything works except for connecting these two pieces.
ToDoListController.h:
ToDoListController.m:
I'm currently going through the Aaron Hillegass book, and I am doing the challenge at the end of Chapter 6. The challenge is to create a program with 3 controls (NSTextField for input, NSTableView for display, and an NSButton to add what's in the NSTextField to the NSTableView. The program is supposed to be a 'To Do List').
How do I attach/connect my array to the NSTableView? I am interested in doing this via Outlets (not through binding).
Here is the code I have so far. Everything works except for connecting these two pieces.
ToDoListController.h:
Code:
#import <Cocoa/Cocoa.h>
@interface ToDoListController : NSObject {
IBOutlet NSTableView *tvToDoList;
IBOutlet NSTextField *txtInput;
NSMutableArray *toDoList;
}
- (IBAction)cbAddEntry:(id)sender;
@end
ToDoListController.m:
Code:
#import "ToDoListController.h"
@implementation ToDoListController
-(id)init
{
if (![super init])
return nil;
toDoList = [[NSMutableArray alloc] init];
return self;
}
-(int)numberOfRowsInTableView:(NSTableView *)tv
{
return [toDoList count];
}
-(id)tableView:(NSTableView *)tv
objectValueForTableColumn:(NSTableColumn *)tableColumn
row:(int)row
{
NSString *value = [toDoList objectAtIndex:row];
return value;
}
-(IBAction)cbAddEntry:(id)sender
{
NSString *sUserInput = [txtInput stringValue];
NSLog(@"sUserInput=%@", sUserInput);
[toDoList addObject:sUserInput];
NSLog(@"toDoList={%@}", toDoList);
[txtInput setStringValue:@""];
}
@end
Last edited: