So the challenge is to make a To Do List with a TextField, TableView and a MutableArray.
I can add items to the array but I can't figure out how to update the TableView with the array contents. I'm pretty sure I've made the right connections in IB.
This is my code so far.
I can add items to the array but I can't figure out how to update the TableView with the array contents. I'm pretty sure I've made the right connections in IB.
This is my code so far.
Code:
//
// ToDoList.h
// ToDoList
//
// Created by Robert Litchfield on 7/05/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface ToDoList : NSObject {
NSMutableArray *toDoList;
IBOutlet NSTableView *tableView;
IBOutlet NSTextField *textField;
}
-(IBAction)addEntry:(id)sender;
-(id)init;
-(id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row;
-(int)numberOfRowsInTableView:(NSTableView *)tv;
@end
Code:
//
// ToDoList.m
// ToDoList
//
// Created by Robert Litchfield on 7/05/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "ToDoList.h"
@implementation ToDoList
-(id)init {
[super init];
toDoList = [[NSMutableArray alloc] init];
NSLog(@"Init Succesful");
return self;
}
-(IBAction)addEntry:(id)sender {
[toDoList addObject:[textField stringValue]];
NSLog(@"Entry Added");
NSLog(@"Array now:");
for (NSString *ts in toDoList)
NSLog(@"%@", ts);
}
-(int)numberOfRowsInTableView:(NSTableView *)tv {
return [toDoList count];
}
-(id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row {
NSString *c = [toDoList objectAtIndex:row];
return c;
}
@end