Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inconsistent state of NSSplitView

I am playing around with NSSplitView - quite successfully for now but here is my Problem:

My SplitView looks like this: SplitView

Test project here: https://www.dropbox.com/s/amz863l11nvkdir/TestNSSplitView.zip

I've implemented - (void)splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize to stick the left and the right subview at the same size as before while resizing.

If I open the Window which contains the NSSplitView this message comes up in the console:

<NSSplitView: 0x107de1520>: the delegate <BRSchematicWindowController: 0x10ac11050> was sent -splitView:resizeSubviewsWithOldSize: and left the subview frames in an inconsistent state:
Split view bounds: {{0, 0}, {1068, 600}}
     Subview frame: {{0, 0}, {182, 600}}
     Subview frame: {{183, 0}, {640, 600}}
     Subview frame: {{824, 0}, {243, 600}}
The outer edges of the subview frames are supposed to line up with the split view's bounds' edges. NSSplitView is working around the problem, perhaps at the cost of more redrawing. (This message is only logged once per NSSplitView.)

What is wrong here? I didn't get it even after reading this message...

PS: In the right splitView there is another NSSplitView this isn't the failure. I get this message even without this additional NSSplitView.

like image 943
tuna Avatar asked Apr 28 '13 20:04

tuna


1 Answers

If you're targeting OS X 10.6+, then it's much easier to use NSSplitView's splitView:shouldAdjustSizeOfSubview: to control sizing.

One way to use this method would be to add the following IBOutlets to your .h file:

@property (nonatomic, weak) IBOutlet NSView *leftView;
@property (nonatomic, weak) IBOutlet NSView *centerView;
@property (nonatomic, weak) IBOutlet NSView *rightView;

Then implement splitView:shouldAdjustSizeOfSubview: in your .m file like this:

- (BOOL)splitView:(NSSplitView *)aSplitView
             shouldAdjustSizeOfSubview:(NSView *)subview {
    return (subview == _centerView);
    // or return !(subview == _leftView || subview == _rightView);
}

By implementing that, you basically say "only adjust the size of center subview when resizing".

You can comment out the entire splitView:resizeSubviewsWithOldSize: method for the time being unless you need to customize the default behavior in some way.

Note that if you have multiple split views that have this controller object set to be their delegate, you may want to check to see which split view is being passed in the aSplitView parameter and do different things accordingly.

like image 102
NSGod Avatar answered Nov 06 '22 19:11

NSGod