In the IB palette (v3.0), it shows the various cells centered both
horizontally and vertically, but when used in a tableView, my cell
appears at the top, not vertically centered. Resizing the column only
auto-resizes the level cell elements.
Can you think of a way I can get the cell itself vertically centered as
in the IB palette?

Signature
/los "I was a teenage net-random."
slashlos - 10 Feb 2008 00:55 GMT
> In the IB palette (v3.0), it shows the various cells centered both
> horizontally and vertically, but when used in a tableView, my cell
[quoted text clipped - 3 lines]
> Can you think of a way I can get the cell itself vertically centered as
> in the IB palette?
OK I subclassed NSLevelIndicatorCell to VALevelIndicatorcell taking a
cue from a similar issue with NSTextFieldCell as follows:
#import <Cocoa/Cocoa.h>
@interface VALevelIndicatorCell : NSLevelIndicatorCell
{
@private
BOOL _vAlign;
}
- (BOOL)isVerticallyAligned;
- (void)setVerticalAlignment:(BOOL)value;
@end
#import "VALevelIndicatorCell.h"
@implementation VALevelIndicatorCell
- (id) init
{
if (self = [super init])
{
_vAlign = TRUE;
}
return self;
}
- (void)drawWithFrame:(NSRect)frame inView:(NSView *)controlView
{
if (_vAlign)
{
int i = (frame.size.height - [self cellSize].height)/2;
frame.origin.y += i;
frame.size.height -= i;
}
[super drawWithFrame:frame inView:controlView];
}
- (BOOL) isVerticallyAligned
{
return _vAlign;
}
- (void) setVerticalAlignment:(BOOL)value
{
_vAlign = value;
}
@end
which visually appears centered but the cell doesn't respond to user
actions (i.e., acts like it's disabled). I had set the cell's class to
my class in IB, and primed the column's cell in my table view like this
- (void)awakeFromNib
{
// Vertically align our start column control
NSTableColumn * column = [tableView tableColumnWithIdentifier:@"1"];
VALevelIndicatorCell * cell = [column dataCell];
[cell setVerticalAlignment:YES];
}
So while I visually got the results I was seeking, the column's cell
isn't responsive; what'd I miss?

Signature
/los "I was a teenage net-random"
slashlos - 22 Feb 2008 01:09 GMT
No one? I notice that even though in IB I set the class for the cell to
mine it won't appear in IB so I was thinking I need to create it in IB
and there's no book / how-to yet on that.
But in my awakeFromNib code the code I'd shown does get my cell
displayed but as I said earlier I can't seem to manipulate it. The class
features NSCopying and NSCoding support but I've since been stuck.
Help! TIA!!

Signature
/los "I was a teenage net-random"
slashlos - 23 Feb 2008 15:55 GMT
Ok, let's try again, using
http://www.mikeash.com/?page=pyblog/custom-nscells-done-right.html
as a guide and the fix suggested for nested cells, I came up with this
sub-class of a level indicator:
#import <Cocoa/Cocoa.h>
@interface VALevelIndicatorCell : NSLevelIndicatorCell {} @end
@implementation VALevelIndicatorCell
+ (Class)cellClass
{
return [VALevelIndicatorCell class];
}
- (void)drawWithFrame:(NSRect)frame inView:(NSView *)controlView
{
int i = (frame.size.height - [self cellSize].height)/2;
frame.origin.y += i;
frame.size.height -= i;
[super drawWithFrame:frame inView:controlView];
}
@end
While I find my draw method does get called, and the cell does get drawn
centered, no user interaction is possible.
This may or may not be related but I notice that the <go to counterpart>
button for my header goes nowhere, while viewing the .m sources does!
Short or rebuilding the class, is there a way to mend a counterpart's
linkage (header or source)?

Signature
/los "I was a teenage net-random"