I am having problems in Hillegass book, chapter 6, the very last page, Challenge: make a data source. Pretty much, my table view is not updating any of the data. and when I do [tableView reloadData] my program crashes.
The basic premis is that you have an input field and an add button. What ever is in the input field gets added to the list and displayed in tableView.
Here is my code.
and all my connections using interface builder
The basic premis is that you have an input field and an add button. What ever is in the input field gets added to the list and displayed in tableView.
Here is my code.
Code:
#import <Cocoa/Cocoa.h>
@interface AppController : NSObject {
IBOutlet NSTextField *textField;
IBOutlet NSButton *addButton;
IBOutlet NSTableView *tableView;
NSMutableArray *toDoList;
}
- (IBAction)add:(id)sender;
@end
Code:
@implementation AppController
- (id)init
{
[super init];
//Logs used for debugging
NSLog(@"init");
toDoList =[[NSMutableArray alloc] init];
return self;
}
-(IBAction)add:(id)sender
{
NSString *string = [textField stringValue];
//is the string zero length?
if([string length] == 0)
{
NSLog(@"string from %@ is of zero length",textField);
return;
}
[toDoList addObject: (id)string];
NSLog(@"string from %@",toDoList);
}
- (int)numberOfRowsInTableView:(NSTableView *)tv
{
NSLog(@"number of list %@",[toDoList count]);
return [toDoList count];
}
-(id)tableView:(NSTableView *)tv
objectValueForTableColumn:(NSTableColumn *)tableColumn
row:(int)row
{
NSString *v = [toDoList objectAtIndex:row];
NSLog(@"string from List%@",v);
return v;
}
@end
and all my connections using interface builder