Re: Passing arguments through a binding
Re: Passing arguments through a binding
- Subject: Re: Passing arguments through a binding
- From: Nathan Auch <email@hidden>
- Date: Thu, 20 Dec 2007 11:19:35 -0500
Jean-Daniel Dupas wrote:
Le 20 déc. 07 à 15:26, Nathan Auch a écrit :
Shripad Hebbar wrote:
My application is one of several front-ends to a shell-script based
installer. The back-end runs on multiple platforms and provides all of
the resources (strings) to the various front-ends upon request. It is
not feasible to restructure this application so that the Cocoa based
front-end uses resources from a NIB-file, they need to be provided by
the back-end at runtime.
Obviously you have to use bindings where titles of each of you
controls need to be bound to a controller
object which could be a kind of facade to your strings that come
from your back-end.
Does this mean that in my controller object I need to have a unique
method or instance variable for each string that I want to localize?
I was kind of hoping to find something a little less verbose.
If possible, I'd like to avoid having to manually query for each
internationalized string in code. I'm a Cocoa newbie, so maybe
there is
something obvious that I'm missing, but it looks like unless I can
pass
an argument to a binding, I'm basically out of luck.
As I said, write a facade which hides all the details as how the
title strings are generated. Have clean
KVC compliant methods to return those titles. And in NIB bind your
controls to appropriate keys
governed by the KVC compliant methods. Read more on KVC-KVO :
http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/CocoaBindings.html
The code that generates the strings is already well abstracted, I
guess I should have said "I'd like to avoid having to implement a
unique method for every string". What I would like to do is bind all
of my controls to the same key (i.e. controller.getTitle) and pass an
argument when calling the method associated with the key, but I'm
pretty sure this isn't possible. If there is a way to accomplish
this, or some other clever way to accomplish my end goal, I'm all ears.
However there would be a problem where localized strings may have
different sizes in different languages and
you will have to take care that your controls are properly resized
to fit the title.
I understand this issue and will deal with it accordingly.
Thank you for your reply and help,
-Nathan
Have a look at -[NSObject valueForUndefinedKey:].
http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Protocols/NSKeyValueCoding_Protocol/Reference/Reference.html
You can override this method like this:
- (id)valueForUndefinedKey:(NSString *)key {
NSString *value = NSLocalizedString(key, nil, nil);
if (!value)
return [super valueForUndefinedKey:key];
else
return value;
}
This is exactly what I was looking for. Thank you very much!
-Nathan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden