Created
June 8, 2011 20:06
-
-
Save pikajude/1015267 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // DDMessageController.h | |
| // dAmnDesktop | |
| // | |
| // Created by Joel on 4/24/11. | |
| // Copyright 2011 __MyCompanyName__. All rights reserved. | |
| // | |
| #import <Cocoa/Cocoa.h> | |
| #include "DDMessageView.h" | |
| @interface DDMessageController : NSObject { | |
| IBOutlet DDMessageView *messageView; | |
| IBOutlet NSTextField *textField; | |
| } | |
| - (IBAction)addMessage:(id)sender; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // DDMessageController.m | |
| // dAmnDesktop | |
| // | |
| // Created by Joel on 4/24/11. | |
| // Copyright 2011 __MyCompanyName__. All rights reserved. | |
| // | |
| #import "DDMessageController.h" | |
| @implementation DDMessageController | |
| - (id)init | |
| { | |
| self = [super init]; | |
| messageView = [[DDMessageView alloc] init]; | |
| return self; | |
| } | |
| - (IBAction)addMessage:(id)sender | |
| { | |
| NSLog(@"attempting to add an item"); | |
| NSDictionary *newMessage = [NSDictionary dictionaryWithObject:[textField stringValue] forKey:@"messages"]; | |
| [messageView addRow:newMessage]; | |
| } | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // DDMessageView.h | |
| // dAmnDesktop | |
| // | |
| // Created by Joel on 4/24/11. | |
| // Copyright 2011 __MyCompanyName__. All rights reserved. | |
| // | |
| #import <Cocoa/Cocoa.h> | |
| @interface DDMessageView : NSTableView <NSTableViewDelegate,NSTableViewDataSource> { | |
| NSMutableArray *_items; | |
| } | |
| - (NSMutableArray *)items; | |
| - (id)selectedRowItemForColumnIdentifier:(NSString *)anIdentifier; | |
| - (void)setItems:(NSMutableArray *)anArray; | |
| - (void)addRow:(NSDictionary *)item; | |
| - (void)removeRow:(unsigned)row; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // DDMessageView.m | |
| // dAmnDesktop | |
| // | |
| // Created by Joel on 4/24/11. | |
| // Copyright 2011 __MyCompanyName__. All rights reserved. | |
| // | |
| #import "DDMessageView.h" | |
| @implementation DDMessageView | |
| - (id)init | |
| { | |
| self = [super init]; | |
| _items = [[NSMutableArray alloc] init]; | |
| [self setDelegate:self]; | |
| [self setDataSource:self]; | |
| [self reloadData]; | |
| return self; | |
| } | |
| - (void)dealloc | |
| { | |
| [_items release]; | |
| [super dealloc]; | |
| } | |
| - (NSMutableArray *)items { | |
| return _items; | |
| } | |
| - (id)selectedRowItemForColumnIdentifier:(NSString *)anIdentifier | |
| { | |
| if ([self selectedRow] != -1) | |
| return [[_items objectAtIndex:[self selectedRow]] objectForKey:anIdentifier]; | |
| return nil; | |
| } | |
| - (void)setItems:(NSMutableArray *)anArray | |
| { | |
| if (_items == anArray) | |
| return; | |
| [_items release]; | |
| _items = anArray; | |
| [_items retain]; | |
| [self reloadData]; | |
| } | |
| - (void)addRow:(NSDictionary *)item | |
| { | |
| NSLog(@"count before: %lu", [_items count]); | |
| [_items addObject:item]; | |
| NSLog(@"count after: %lu", [_items count]); | |
| [self reloadData]; | |
| } | |
| - (void)removeRow:(unsigned)row | |
| { | |
| [_items removeObjectAtIndex:row]; | |
| [self reloadData]; | |
| } | |
| - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView | |
| { | |
| return [_items count]; | |
| } | |
| - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row | |
| { | |
| if (row != -1) | |
| return [[_items objectAtIndex:row] objectForKey:[tableColumn identifier]]; | |
| return nil; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment