Re: Chapter 6 Challenge Help!
Re: Chapter 6 Challenge Help!
- Subject: Re: Chapter 6 Challenge Help!
- From: email@hidden
- Date: Thu, 17 Jul 2008 08:40:16 +0200
Hi Eric,
everything correct so far (datasource, IBAction). You have to write some
methods for the NSTableDataSource protocol.
Here is what worked for me:
//
// AppController.h
// ToDoList
//
// Created by Tom on 04.07.08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface AppController : NSObject {
IBOutlet NSTextField *textField;
IBOutlet NSTableView *tableView;
NSMutableArray *array;
}
- (IBAction) add:(id) sender;
@end
//
// AppController.m
// ToDoList
//
// Created by Tom on 04.07.08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "AppController.h"
@implementation AppController
- (id) init
{
[super init];
array = [[NSMutableArray alloc] init];
return self;
}
- (IBAction) add:(id) sender
{
NSString *string = [textField stringValue];
NSLog(@"Got string %@ from textfield", string);
[array addObject:string];
[tableView reloadData];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [array count];
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:
(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
return [array objectAtIndex:rowIndex];
}
- (void)tableView:(NSTableView *)aTableView setObjectValue:anObject
forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
{
[array replaceObjectAtIndex:rowIndex withObject:anObject];
}
@end
Hope this helps,
Tom
Am 17.07.2008 um 05:33 schrieb Eric Lee:
First of all, I'm' new to cocoa, so I'm a beginner that just
started. I'm trying to make the To-Do list on Chapter 6 from Aaron's
new book, Cocoa Programming for Mac OS X Third Edition.
I've made an NSMutableArray, set the data source of the NSTableView
to AppController, made an IBACTION and connected it to a Button,
made a text field, and connected the AppController and the text
field, and made an outlet for the table view, and connected it to
the app controller.
For the .m file, I used:
NSString *string = [textField stringValue];
[array insertObject:string atIndex:0];
Then I got stuck....
Help please?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden