Cocoa Bindings Clarification
Cocoa Bindings Clarification
- Subject: Cocoa Bindings Clarification
- From: Mark Grimes <email@hidden>
- Date: Fri, 12 Nov 2004 13:29:24 -0800
After reading numerous articles and references on Cocoa Bindings, I am
not able to bridge-gap the knowledge for using it on a particular
application I am working
on. I see many references to usage in a NSTableView, but not a lot of
references to how one would use it for other applications.
For example,
I have a piece of code I am writing that implements a NSTask (Cocoa
wrapper for UNIX app) for a utility that has MANY command line
switches.
I have a interface I implemented in IB that contains many NSButton's
and NSTextField's. In fact there are approximately 50 outlets
associated
with the NIB.
When I look at the code required to say things like "If this radio
button is checked, then mark the NSTextField's associated with the
other radio
buttons as un-editable (aka grayed out)... it makes me think there has
to be a better way to remove hundreds of lines of updateUI glue-code.
Also for a more detailed example I have a NSTextField for entering in a
path to a file. A button next to it utilizes a NSOpenFile to allow
selecting
a file from the GUI, and then treating the NSTextField with the
results. I have several of these due to many command line switches
requesting paths to filenames.
Each of these are currently separate IBAction methods, seeming
enormously redundant due to the methods only varying by a couple
lines... Below is what I am referring to:
- (IBAction)chooseLogin:(id)sender
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setCanChooseDirectories:NO];
[panel setCanChooseFiles:YES];
[panel setAllowsMultipleSelection:NO];
[panel beginSheetForDirectory:NSHomeDirectory()
file:nil
types:nil
modalForWindow:mainWindow
modalDelegate:self
didEndSelector:@selector
(chooseLoginOpenPanelDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
- (void)chooseLoginOpenPanelDidEnd:(NSOpenPanel *)sheet
returnCode:(int)returnCode
contextInfo:(void *)contextInfo
{
if (returnCode == NSOKButton)
{
NSString *userFile = [[sheet filenames] objectAtIndex:0];
[loginFileField setStringValue:userFile];
}
}
- (IBAction)choosePassword:(id)sender
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setCanChooseDirectories:NO];
[panel setCanChooseFiles:YES];
[panel setAllowsMultipleSelection:NO];
[panel beginSheetForDirectory:NSHomeDirectory()
file:nil
types:nil
modalForWindow:mainWindow
modalDelegate:self
didEndSelector:@selector
(choosePasswordOpenPanelDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
- (void)choosePasswordOpenPanelDidEnd:(NSOpenPanel *)sheet
returnCode:(int)returnCode
contextInfo:(void *)contextInfo
{
if (returnCode == NSOKButton)
{
NSString *passwordFile = [[sheet filenames] objectAtIndex:0];
[passwordFileField setStringValue:passwordFile];
}
}
Is there 1) a better way to implement these methods without a lot of
repeat code? and 2) is there a way of utilizing Cocoa Bindings to do
away with the IBOutlets
as described above and IBActions like pasted above. With respect to
#1, is there a way to combine chooseLogin and choosePassword and set a
conditional for didEndSelector, as this would shorten the length of the
redundancy.
It seems to me that Cocoa Bindings provides so many advantages to doing
away with gluecode and handling the controller layer, but I don't see
many representative examples other then taking care of the obvious
dataSource issues with NSTableViews.
Any information would be appreciated!
--
Mark Grimes
Mac OS X Software Developer
email@hidden
_______________________________________________
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