Reputation: 9770
I would like to bind NSTableColumn's headerTitle property to an NSMutableArray in my model layer (via an NSArrayController).
Basically I want to have an array where I can change values and have the table column header titles update. Is that reasonable?
However, the headerTitle
binding wants an single NSString
and I'm not sure how to connect my model object to this binding via my NSArrayController
. Google does not give many hits for this problem.
My model layer consists of two class (both of which are appropriately KVC compliant). The first is a model which represents a single column title, it has one property title
,
// A model class representing the column title of single NSTableColumn
@interface ColumnTitle : NSObject
@property NSString *title;
+ (ColumnTitle*) columnTitleWithTitle:(NSString*) aString;
@end
The second a model object which represents an ordered group of ColumnTitle objects,
// Class representing an order collection of model items
@interface TableColumnTitles : NSObject
@property NSMutableArray* columnTitles; // an array of ColumnTitle objects
// These are the KVC array accessors
-(void) insertObject:(ColumnTitle*)columnTitle inColumnTitlesAtIndex:(NSUInteger)index;
- (void)removeObjectFromColumnTitlesAtIndex:(NSUInteger)index;
- (void)replaceObjectInColumnTitlesAtIndex:(NSUInteger)index withObject:(ColumnTitle*)columnTitle;
@end
Note that TableColumnTitles
object implements the above array accessors which are required for the bindings. Any suggestions?
Upvotes: 2
Views: 145
Reputation: 6638
Haven't tried that before but what you're actually asking for is using KVC for array indexes. A quick google didn't turn up anything on that issue except some results that indicate it's not (yet) possible (check this)
The easiest work-around I could come up with would be to simply add dedicated properties for the array indexes.. not nice but does the job.
So for a NSMutableArray
called myArray
and contains objects with title
properties of type NSString
you'd do something like:
@property (nonatomic, readonly, getter = columnOneGetter) NSString *columnOneString;
(NSString*) columnOneGetter
{
return myArray[0].title;
}
Always assuming of course their number is known in advance and we're not talking 200 columns :-)
Upvotes: 1
Reputation: 1546
I think this may/may not be what you're after, but quick google search landed me here: http://pinkstone.co.uk/how-to-add-touch-events-to-a-uitableviewfooter-or-header/
edit: i realize this is for mac (not ios) but should be pretty easy to translate if it actually helps.
Upvotes: 0