当点击它时,NSOutlineView会以10.9翻转

时间:2014-02-26 10:01:50

标签: macos cocoa nsoutlineview

我有一个基于单元格的NSOutlineView,因为我已经对NSTextfieldCell进行了分类,我编写了以下代码。

-(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {

    // A single cell instance is used to render every row, so we can't store the 
    // custom view here

    NSRect bgFrame = cellFrame;
    bgFrame.size.width = bgFrame.size.width + bgFrame.origin.x + 3;
    bgFrame.origin.x = 0;

    if ([self isHighlighted])
    {
        [[NSColor blackColor] set];  
        NSRectFill(bgFrame);
    }
    else
    {
        NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:[NSColor whiteColor] endingColor:[NSColor lightGrayColor]];
        [gradient drawInRect:bgFrame angle:90];
    }


    [controller showViews:controlView frame:bgFrame highlight:[self isHighlighted] && !isEditing];
}

在视图控制器中

-(void)showViews:(NSView*)parent frame:(NSRect)cellFrame highlight:(BOOL)highlight
{
    NSView* nestedView;
    nestedView = menu100;
   [nestedView setFrame: cellFrame];

    if ([nestedView superview] != parent)
    {
        [nestedView prepareContentInRect:[nestedView visibleRect]];
        [parent addSubview: nestedView];
    }

}

 nestedView = menu100; menu100 is a `NSView` with `NSOutlineview`

menu100视图  enter image description here

NSOutlineView

- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {

    if ([item isKindOfClass:[NSDictionary class]]) {
              [cell setBackgroundColor:[NSColor keyboardFocusIndicatorColor]];

    }
    else
    {
        if (item!=nil) {

            CustomCellController* cellCtrl = [cellViewControllers objectForKey:item];
            if (!cellCtrl)
            {
                cellCtrl = [[CustomCellController alloc] initWithMenu:item];
                [cellViewControllers setObject:cellCtrl forKey:item];
            }
            CustomCell* mycell = cell;
            [mycell setController:cellCtrl];
        }
    }
}

现在视图看起来像这样    before clicking

现在当我点击儿童轮廓视图时,它会被翻转。 enter image description here

上面的代码在10.8中工作,但它在10.9中被翻转。我对此感到很生气。任何人都可以建议在10.9中摆脱这个。

0 个答案:

没有答案