Here is this question version with images. I can't post it because of Stackoverflow policy concerning spam.
Hello!
I'm learning Cocoa, and I've got a problem: I would like to bind the content of an NSMutableArray to an NSTableView, with bindings. I read many documentations about them, but I can't manage to make them work (nothing is displayed in my table).
Here are the facts:
I created a simple model, called MTMTask
which contains 2 properties, priority
and text
:
MTMTask.h
@interface MTMTask : NSObject {
NSString *priority;
NSString *text;
}
@property(copy) NSString* priority;
@property(copy) NSString* text;
- (id) initWithPriority :(NSString*)newPriority andText:(NSString*)newText;
@end
MTMTask.m
#import "MTMTask.h"
@implementation MTMTask
@synthesize text, priority;
- (id) initWithPriority:(NSString *)newPriority andText:(NSString *)newText {
if (self = [super init]) {
priority = newPriority;
text = newText;
return self;
}
return nil;
}
@end
Then I've created the MTMTaskController :
MTMTaskController.h
#import <Cocoa/Cocoa.h>
#import "MTMTask.h"
@interface MTMTaskController : NSObject {
NSMutableArray *_tasksList;
}
- (NSMutableArray *) tasksList;
@end
MTMTaskController.m
#import "MTMTaskController.h"
@implementation MTMTaskController
- (void) awakeFromNib
{
MTMTask *task1 = [[MTMTask alloc] initWithPriority:@"high" andText:@"Feed the hungry cat"];
MTMTask *task2 = [[MTMTask alloc] initWithPriority:@"low" andText:@"Visit my family"];
_tasksList = [[NSMutableArray alloc] initWithObjects:task1, task2, nil];
}
- (NSMutableArray*) tasksList
{
return _tasksList;
}
@end
And finally I edited the MainMenu.xib: I added a NSObject
and set its class to MTMTaskController
. Then I added an NSArrayController, called TasksListController
, with its content outlet bound to MTMTaskController.tasksList
. I also set its mode to Class
and class name MTMTask
. I bound the value
outlet of two columns of an NSTableView
to TasksListController
text and priority.
But when I run the program, well, it's not really a success: nothing shows up in the table.
Have you got an idea concerning my problem? I think I'm missing something but I can't figure what.
Thanks in advance!