Re: Cocoa Bindings, NSMatrix, setting programmatically
Re: Cocoa Bindings, NSMatrix, setting programmatically
- Subject: Re: Cocoa Bindings, NSMatrix, setting programmatically
- From: Renaud Boisjoly <email@hidden>
- Date: Wed, 28 Apr 2004 14:43:14 -0400
Oh, buy... communication... let me do this again, with source (see end
of mail for a link) and more...
I'm creating a tool which manages events occurring at specific
intervalls.
I have a Class called MCTask which contains the following properties:
NSString *taskName;
NSMutableArray *weekdays;
NSMutableArray *hours;
NSMutableArray *minutes;
and proper methods to access them (built with Accessorizer):
- (NSMutableArray *)weekdays;
- (void)setWeekdays:(NSMutableArray *)newWeekdays;
etc.
In Interface builder, I have an array controller, which managers an
array of MCTasks.
I have a table which displays the task name and has buttons to add,
delete and edit each MCTask.
I think all this is ok...
Each task has a set of controls in the details window to assign
specific weekdays, hours and minutes for this task to occur.
They are basically matrices (I dragged an NSMatrix from the palette and
made it 7 items high, 1 item wide, text-only and changed the Title of
each cell to the day of the week.
In the bindings for the matrix, I chose my MCTaskController (the same
array controller as above), set the controller key to "selection" and
the value to "weekdays".
So in essence, the controller is managing an array of MCTask objects
and each of these has an array property called weekdays which contains
the selected items in the matrix. So if I click, shift click or control
click in the matrix, it sets the weekdays array to an array containing
each of the Titles of the cells in the NSMatrix. It works. I simply
cannot set a default value for this array and have it reflected in the
matrix from the start. I want to set the default day to "Monday" when
the user creates a new Task.
I was trying to set the weekdays array for each MCTask to an array
containing a single NSString "Monday" but although it sets it
correctly, the interface doesn't reflect it. It may be that I was
setting the array before any notification system was initialized... I
was doing it in the init method of MCTask this way:
- init
{
if (self = [super init]) {
//Define default values...
NSLog(@"Init MCTask");
[self setWeekdays:[NSMutableArray arrayWithObject:@"Monday"]];
}
return self;
}
On Apr 28, 2004, at 1:44 PM, Allan Odgaard wrote:
On 28. Apr 2004, at 14:46, Renaud Boisjoly wrote:
Let me try another shot at describing the setup...
But no source? :)
I've created an NSArrayController to manage an object which contains
different properties, like an event name, weekdays it should occur
on, hours it should occur on, etc.
An array controller to manage an object? Do you actually mean to
manage an array of objects, and that each object have the properties
you mention?
Yes, an array of MCTaks, each containing a few arrays for weekdays,
hours and minutes as well as string for the name
I've bound the NSMatrix's selectedValues to my NSArrayController
using "selectedObjects" and the value "weekdays".
Is this the same array controller as before? Or do you have one array
controller for all the objects and then another array controller for
the weekdays, which contentArray and/or selectedObjects is bound to a
key path involving the selected object of the first array controller?
Same array controller. I'm really managing the selection in the
NSMatrix, I want to keep which buttons are down, the actual values
(titles of the buttons) stay the same for each occurrence of MCTask...
I'm getting the feeling I'm not doing this correctly, even if it does
work (apart for setting defaults).
But when I set the array programmatically, using [self
setAllWeekdays:[NSMutableArray arrayWithObject:@"Monday"]; the array
is set, but the interface doesn't reflect it.
Above you said you had bound the value to 'weekdays', so changing that
value, assuming it is the same, should be done with the setWeekdays:
accessor or using setValue:forKeyPath: with "weekdays" in the key
path.
Yes, I tried setWeekdays (my original line said setAllWeekdays, an
error in the email but not the actual code, remnants from a test I
did...), but perhaps doing it in the init method of the MCTask is
wrong? When else can I do this...
I also notice that you send the method to 'self', does that mean that
it is the object itself which sets a default weekday array? is this
object created by the array controller?
Yes, I was trying for the MCTask to set its own defult value... I'm
guessing this is not right... whew, I should've taken programming
classes ;-)
Am I wrong in assuming the content of this array is a simple
NSString? Must I use a reference to the NSCell itself (where am I
going to get that, through an outlet perhaps?
I am still not sure exactly how you hookup things, but I am sure that
you would not have to use NSCell instances -- I am almost certain that
a string array is the proper thing if I understand you correctly.
I'm just trying to manage the selection in the matrix of buttons... as
a property for an MCTask object... but the array built by the Binding
system is an array of NSStrings...
Sorry, I'm a newbie at all this, thanks for all your help! Let me
know if this isn't clearer...
The best way is really to a) describe the task that needs to be solved
in an as abstract way as possible (so to avoid all those details which
generally needs a diagram to explain and/or leads to misunderstandings
;) ) and b) provide source code (but trying to limit it to only the
essential parts, i.e. 5-15 lines)!
Boy, thanks so much for your patience exaplining... I've created a
sample project so you can see how I've done it. You can download it
from
http://homepage.mac.com/renaud/.cv/renaud/Public/TestBindings.zip-
link.zip and see what you can tell from that. Probably a better way.
Thanks so much for all your time!
- Renaud
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.