Wednesday, October 14, 2009

Instant Cocoa: Checkbook project 5


Elementary bindings for the UI


There are seven columns in the table view. None of them is complicated.

• date
• check no.
• name
• amount
• balance
• deposit
• clear


These are all bound via an NSArray controller to the objects in the checkbookItemsArray in MyDocument. Some have a formatter dropped onto the cell. -date has a date formatter (naturally) and amount and balance have number formatters.



The text color of • amount is bound to isDeposit a via ColorFormatter, the binding and class definition is exactly as described previously.



The only one that is more complex is • balance. But I think I will postpone talking about that binding until I discuss the code too.

There are 3 additional UI elements bound to a dedicated class, "MyUISettings." As you'd expect, we keep them synchronized with bindings mechanism. The code is elementary. We provide reasonable default values to start with.


#import <Cocoa/Cocoa.h>

@interface MyUISettings : NSObject {
}

@property (retain) NSNumber *segmentedButtonSelection;
@property (retain) NSNumber *autoNumber;
@property (retain) NSNumber *autoDate;

@end

#import "MyUISettings.h"

@implementation MyUISettings

@synthesize segmentedButtonSelection;
@synthesize autoNumber;
@synthesize autoDate;

- (id)init {
self = [super init];
if (self) {
}
//[self setClearedOnly:[NSNumber numberWithBool:NO]];
[self setSegmentedButtonSelection:
[NSNumber numberWithInt:0]];
[self setAutoNumber:[NSNumber numberWithBool:YES]];
[self setAutoDate:[NSNumber numberWithBool:YES]];
return self;
}

@end