Search code examples
objective-cmacoscocoanssplitview

NSSplitView delegate method is not invoked


I am trying to fix the divider inside NSSplitView. Found how it is done at http://www.cocoabuilder.com/archive/cocoa/202611-fixed-width-of-pane-in-nssplitview.html Hope that it will work fine, yet I cannot even test this...

I am [hopefully] setting delegate for my SplitView class by executing the below line of code:

[self.mySplitView setDelegate:self.mySplitView];

The SplitView class implementation is also implementing the delegate as below:

@interface PanelSplitView : NSSplitView <NSSplitViewDelegate>

Inside Objective-C implementation, I have the following method:

-(void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:(NSSize)oldSize
{
    NSLog(@"Resizing SplitView subviews");

    CGFloat dividerThickness = [sender dividerThickness];
    NSRect leftRect  = [[[sender subviews] objectAtIndex:0] frame];
    NSRect rightRect = [[[sender subviews] objectAtIndex:1] frame];
    NSRect newFrame  = [sender frame];

    leftRect.size.height = newFrame.size.height;
    leftRect.origin = NSMakePoint(0, 0);
    rightRect.size.width = newFrame.size.width - leftRect.size.width
- dividerThickness;
    rightRect.size.height = newFrame.size.height;
    rightRect.origin.x = leftRect.size.width + dividerThickness;

    [[[sender subviews] objectAtIndex:0] setFrame:leftRect];
    [[[sender subviews] objectAtIndex:1] setFrame:rightRect];
}

Since there is no log output, I know that the method is never invoked. I understand that implementing the View and the Delegate in the same class might be uncommon, yet I have done it before and it worked every time, so far. Please advise what could I have done wrong.

Thank you


Solution

  • It appears that I did not understand how the [new] NSSplitView works and/or what people meant by fixing the divider position. The delegate method is called on resizing the SplitView, but when the divider is being dragged it is not. Thank you for reading my question.