Newbie Trouble with Basic Bindings
Newbie Trouble with Basic Bindings
- Subject: Newbie Trouble with Basic Bindings
- From: Kane Dijkman <email@hidden>
- Date: Tue, 15 Mar 2005 15:59:30 -0800
Hello folks, I am new to this list. I just found it while searching for
some cocoa help. I am also, coincidentally enough, new to cocoa and
application programming. Up until this point all development I have
done has been web and back end based. None of this newfangled GUI stuff
;-)
So this is where I am hoping someone might be able to help me. I am
working on my second cocoa app (made a small one a year or two ago
(during Tiger)) and I am having a heck of a time with Bindings. I think
I have my head around the the general idea and after many hours of
tinkering I have finally been able to get an NSTableView to display the
values from an NSMutableArray.
The setup for this is pretty simple. I my Controller.h I have:
@interface Controller : NSObject
{
NSString * statusText;
NSMutableArray * listFilesArray;
NSUserDefaults * userDefaults;
FileHandler * fh;
}
And in Controller.m I have a function that is called during -(void)init
to load a set of values:
- (void)loadAvailableLists
{
NSArray *listPath;
if ([self getPreference:@"pathToLists"] != nil)
{
listPath = [fh loadListFiles:[self getPreference:@"pathToLists"]];
}
else
{
listPath = [NSArray arrayWithObject:@"No lists found"];
}
listFilesArray = [NSMutableArray arrayWithArray:listPath];
NSLog(@"listFilesArray count=%d", [listFilesArray count]);
}
This is bound as:
In IB I have an NSArrayController called "listController"
This is bound to "ControllerBindings" which is an NSObjectController
that has an outlet connection to the Controller and also has
"listFilesArray" as an attribute used in the bindings.
Then I have an NSTableView with 1 column with a value binding to
"listController" and a Controller Key of arrangedObjects.
I have put a .sit of the project at <a
href="http://www.digitalemerald.com/livejournal/StockManager.sit">
http://www.digitalemerald.com/livejournal/StockManager.sit</a> for
anyone that might be willing to look at the code or wants a good laugh.
If you do download and run it you will need to enter a preferences path
to a folder of files that should be listed.
So given the information above here are my questions:
1. Am I even remotely doing the binding right? What I want is an Array
of items (in this case files name) to be displayed in the NSTableView.
It is working right now, but I dont think I have it setup right since
it required the listFilesArray in the ControllerBinding too.
2. Provided that question 1 is "yes, this is right" why do programatic
changes to the items in the array not show up in the Table View? If I
just run [listFilesArray addObject:@"penguin"]; it does not show up.
3. How can I find out what values are selected by the user? I want to
be able to show a list of files, have the user click the Run button
(which calls the run method) and I will want to do something based on
their selection. I do not know how to figure out what has been selected
through the Bindings.
4. In general, are there any good books on Bindings? I have scoured the
web and read and reread every tutorial and example on binding over the
last few days and am still not sure how to do much with them. They
sound great, and I really want to learn and understand them but so far
besides some messy code all I have to show for it is a heck of a
headache.
Well, thanks for reading this and if you have any help or suggestions I
would appreciate hearing them.
Oh yeah, I am on 10.3.8 and XCode 1.5 and will be posting this question
on the macosxdev community on LiveJournal as well.
Thanks,
Kane
------------------------------------------------------------------------
---------
If life gives you lemons, squeeze the juice into a watergun and shoot
other people in the eyes.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden