Okay, sort of simple situation. I have a custom NSView which contains an 
NSSlider, an NSTableView, and an NSTextField (a label). The model info is in 
the custom view's view controller and has:

"GraphTableViewController.h"

@interface GraphTableViewController : NSViewController <NSTableViewDataSource>

@property (assign) IBOutlet NSTableView *graphTableView;
@property (nonatomic, retain) NSMutableArray *values;
@property (nonatomic, assign) CGFloat interval;

@end

"GraphTableViewController.m"

@implementation

@synthesize graphTableView;
@synthesize values;
@synthesize interval;
@synthesize intervalLabel;

...

@end

  I have a binding from the NSSlider to self.interval (where self is File's 
Owner in the xib) which works - when the graph data points are added to 
'values', the NSTableView pulls and displays them in two columns, and I can see 
that the evaluation interval is correct. So I thought I'd add a label to show 
what the interval was, right under the slider, and above the table view. I 
control-dragged from the label to right under the @property lines in the 
header, then told it I wanted the property to be called 'intervalLabel' Xcode 
inserted my @property and @synthesize lines for me, and I saved the files. Now 
I want to bind the label to the interval property, but the label's value wants 
to bind to an NSString (i.e. intervalLabel.text), but the property is a 
CGFloat. My first approach was to manually box the values by providing 

@property (nonatomic, readonly) NSString *stringInterval;

then hand-writing the accessor so it converts the self.interval to an NSString

#pragma mark - Non-synthesized accessors

-(NSString *)stringInterval
{
return [NSString stringWithFormat:@"%f",self.interval];
}

  Now, I can bind the label's value to File's Owner's self.stringInterval 
without Xcode/IB complaining.
  I think you can all see where this is going... yep, the label doesn't update 
because it's static; there's nothing to tell the label to ask (through the 
binding) for the self.stringInterval's current value.

1) Is it better to use KVO to observe self.interval somehow from the label, so 
it receives the updated info
2) Bite the bullet and simply update the label's .text property in code when 
the slider's value changes?
-or-
3) is there a way I can directly bind intervalLabel's value to self.interval 
using an NSValueTransformer?

_______________________________________________

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