Okay, clearly I'm still missing something. Let's say I have a model object:

@interface SMPLPlayer : NSObject

...
@property (nonatomic, assign) NSUInteger pcLevel;
...
@end

and now I also have an NSWindowController subclass:

@interface SMPLRollPCWindowController : NSWindowController

...
@property (nonatomic, weak) SMPLPlayer *thePC;
@property (weak) IBOutlet NSTextField *playerLevelLabel; // <- Inserted by 
IB/Xcode
...

@end

  I'm leaving off the majority of the "stuff" for simplicity here. In my 
SMPLRollPCWindowController.xib, I have a window with a label (that I tied to 
the above IBOutlet property in my window controller, via its File's Owner.) Now 
I want to bind the "value" of the label (an NSTextField) to the player object's 
pcLevel property. Unfortunately, I can't simply put in:

Bind to: File's Owner
Model Key Path: self.thePC.pcLevel

because the "value" of the NSTextField is an NSString, while the player 
object's pcLevel property is an NSUInteger. I get a red octagon (in the Model 
Key Path field) if I try. Is this what value transformers are for? Or do I need 
an NSNumberFormatter on the NSTextField first?
  Along the same vein, if I implement my setter for pcLevel as:

-(void)setPcLevel:(NSUInteger)value
{
if (value >= 1)
  {
  self.pcLevel = value;
  }
else
  {
  // Does anything go here?
  }
}

and now, instead of a label, I use a TextField (i.e. the editable one) instead 
of the Label, what do I need to do to make sure the user can't type in invalid 
values for the pcLevel in the TextField (i.e. field-level validation), where 
the model "knows" what valid values are for the field? That is, is there some 
way to code the "else" branch above so the controller object can mediate this 
transfer-of-knowledge between the model and the view, without having to 
hard-code an NSNumberFormatter or some such into the view (which would 
introduce unwanted coupling)?
  TIA! :)




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to