티스토리 뷰

어렵구만. 근디, 재미는 있구만. :-)

//

//  AppController.h

//  MakeDataSource

//

//  Created by JoonHo Son on 09. 9. 8..

//  Copyright 2009 JoonHo Son(s9712094@gmail.com). All rights reserved.

//


#import <Cocoa/Cocoa.h>



@interface AppController : NSObject {

IBOutlet NSTextField *textField;

IBOutlet NSTableView *tableView;

NSMutableArray *array;

}


- (IBAction)addTodo:(id)sender;

@end



//

//  AppController.m

//  MakeDataSource

//

//  Created by JoonHo Son on 09. 9. 8..

//  Copyright 2009 JoonHo Son(s9712094@gmail.com). All rights reserved.

//


#import "AppController.h"



@implementation AppController

#pragma mark -

#pragma mark override methods

- (id)init {

if (![super init]) {

return nil;

}

array = [[NSMutableArray alloc] init];

return self;

}


- (void)dealloc {

[textField release];

[tableView release];

[array release];

[super dealloc];

}


#pragma mark -

#pragma mark private methods

- (void)addTodo:(id)sender {

NSString *string = [textField stringValue];

if ([string length] == 0) {

NSLog(@"You must input TODO text");

return;

}

[array addObject:string];

[tableView reloadData];

[textField setStringValue:@""];

int count = [array count];

int i;

for (i = 0; i < count; i++) {

NSLog(@"%d contents : %@", i, [array objectAtIndex:i]);

}

}


#pragma mark -

#pragma mark delegate methods

- (int)numberOfRowsInTableView:(NSTableView *)tv {

return [array count];

}


- (id)tableView:(NSTableView *)tv

objectValueForTableColumn:(NSTableColumn *)tableColumn

row:(NSInteger)row; {

NSString *v = [array objectAtIndex:row];

return v;

}


- (void)tableView:(NSTableView *)tv

   setObjectValue:(id)object

   forTableColumn:(NSTableColumn *)column

  row:(int)row {

[array replaceObjectAtIndex:row withObject:object];

}

@end



댓글
댓글쓰기 폼