I have a view-based NSTableView that usually has one column in it. However, at a button press, I want a new column to slide in from the left (very similar to what happens on an iPhone when you click the Edit button in Mail). For now, the view that I want to slide is in a very simple view that draws a solid background: its drawRect: just does
[[NSColor blueColor] set];
[[NSBezierPath bezierPathWithRect:[self bounds]] fill];
在代表本人的NSTableView中,我有:
- (IBAction)buttonPressed:(id)sender
{
NSTableColumn *newColumn = [[NSTableColumn alloc] initWithIdentifier:@"InPreviewColumn"];
[newColumn setWidth:40];
[newColumn setMinWidth:[newColumn width]];
/* To make up for there not being an insertColumnAt: method,
hide the column, add it, and move it to the front before showing it. */
[newColumn setHidden:YES];
[availableFontsView beginUpdates];
[availableFontsView addTableColumn:newColumn];
[availableFontsView moveColumn:1 toColumn:0];
[availableFontsView endUpdates];
[newColumn setHidden:NO];
}
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
/* ... code for main column ... */
else if([[tableColumn identifier] isEqualToString:@"InPreviewColumn"])
{
USSolidBackgroundView *v = [tableView makeViewWithIdentifier:[tableColumn identifier] owner:self];
if(!v)
{
v = [[[USSolidBackgroundView alloc] initWithFrame:NSMakeRect(0, 0, [tableColumn width], 0)] autorelease];
[v setIdentifier:[tableColumn identifier]];
[v setAutoresizingMask:NSViewMinXMargin | NSViewWidthSizable | NSViewMaxXMargin];
}
return v;
}
}
Yet, when I do this, I end up with this result (there s a big non-blue margin between the blue part of the new column and the start of the main column):
当增加一栏的斜线出现时,没有差值,因此我很相信问题与另一种观点无关(因为它只看所显示的观点时没有差值)。
我用伐木记录来核实,坚固的彩色观察束总有40个宽度(图形:)而且,至少当形成这种观点时,表列也有40个宽度。
So where does this margin come from? No matter how I size the column, it seem that only roughly half of it is blue. So, the bigger the column, the bigger the margin.
我如何使整个额外一栏成为蓝色?