-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableArrayDelegate.m
68 lines (55 loc) · 1.57 KB
/
TableArrayDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// TableArrayDelegate.m
// Celery
//
// Created by Mark Powell on 11/5/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
//
// TableArrayDelegate.h
// Celery
//
// Created by Mark Powell on 11/5/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "TableArrayDelegate.h"
@implementation TableArrayDelegate
@synthesize delegate;
- (id) init {
if (self = [super init]) {
dataSource = [[NSMutableArray alloc] init];
}
return self;
}
// just returns the item for the right row
- (id) tableView:(NSTableView *) aTableView objectValueForTableColumn:(NSTableColumn *) aTableColumn
row:(int) rowIndex {
FoodData* data = [dataSource objectAtIndex:rowIndex];
if([[aTableColumn identifier] isEqualToString:@"Name"]) {
return data.foodName;
} else if([[aTableColumn identifier] isEqualToString:@"Brand"]) {
return data.brandName;
} else if([[aTableColumn identifier] isEqualToString:@"Description"]) {
return data.shortDescription;
}
return nil;
}
// just returns the number of items we have.
- (int)numberOfRowsInTableView:(NSTableView *)aTableView {
return [dataSource count];
}
- (void) removeAllData {
[dataSource removeAllObjects];
}
- (void) addData:(FoodData*)data {
[dataSource addObject:data];
}
- (void)tableViewSelectionDidChange:(NSNotification *)notification {
NSTableView *view = [notification object];
FoodData* data = [dataSource objectAtIndex:[view selectedRow]];
if([delegate conformsToProtocol:@protocol(FoodListening)]) {
[delegate foodSelected:data];
}
}
@end