Re: Problem with NSTableView in NSSplitView
Re: Problem with NSTableView in NSSplitView
- Subject: Re: Problem with NSTableView in NSSplitView
- From: Peter Zegelin <email@hidden>
- Date: Tue, 24 Nov 2009 22:48:02 +1100
Martin,
I have had the same problem and managed to fix it, but bear in mind I
am a beginner so my solution may not be the best or even correct. I
believe the problem is caused by the tableview being effectively
'turned inside out' if it is inset and the splitview is closed. If
there is no inset the tableviews size will hit 0 on closure but with
an inset it can become negative and stuff something up. I don't think
it is just NSTableviews either as I discovered the fix while trying to
figure out why my simple custom view (no scrollbars) displayed the
same problem.
My solution for my custom view was to add itself as an observer to
receive an NSSplitViewDidResizeSubviewsNotification when the
NSSplitview is resized. I do this in awakeFromNib. This notification
will be sent continuously as the NSSplitview is resized and I do the
following to my custom view:
- (void)splitViewDidResize:(NSNotification *)aNotification{
NSRect rect = [[self superview] bounds];
rect.origin.y = 20;
rect.size.height -= 44;
[self setFrame:rect];
}
The values shown are hard coded and are the offsets of the customview
within the NSSplitview ( I have a placard top and bottom), so yours
will be different.
Now one thing I should mention, I have several views that can be
swapped into the splitview so I have never really figured out which
view [[self superview] bounds] refers to! I think I started with
[self bounds] and worked my way up the chain of parent views until I
found one that worked. In the case of my NSTableview I had to go
further up the chain and find the parent of the NSTableviews scrollbars.
All a bit of a hack but it does work.
Peter
On 23/11/2009, at 6:21 PM, Martin Hewitson wrote:
Dear list,
I'm having some trouble when I have an NSTableView in an
NSSplitView. I have the table set in IB to resize with the view it's
in (all struts clicked). The table does not fill the full view. I
have additionally a button below the table. Both the table and the
button are in the top view of the split view. The problem I have is
that when the splitter is dragged to the top of the window so that
the top view of the split view has zero height, then the splitter is
dragged down again to reveal the top view, the table is not in its
proper position; the column headers are missing, for example.
I'm not sure if this is a Cocoa bug or not, but here's a simple set
of steps to reproduce what I'm seeing.
1) Create a new Cocoa project
2) Open the MainMenu nib in IB
3) Add a split view to the window
4) Size the split view to fill the window and select all its resize/
anchor struts
5) Add a table to the top view of the split view with the top of the
table hitting the top of the view
6) Select all resize/anchor struts of the table
7) Add a button below the table in the top view of the split view
8) Set the button's anchor structs to bottom only
Now build and run and play with the splitter. If the top view
reaches a certain minimum size, then the table position is changed.
I guess I'm setting struts etc wrongly, but I can't figure out quit
what I'm doing wrong. I've uploaded a test project to
http://web.me.com/martinhewitson/BOBsoft/Home/Entries/2009/11/23_Trouble_with_NSSplitview_and_NSTableView_files/SplitViewWithTable.zip
Any clues gratefully received.
Oh, forgot to mention, I'm using Xcode 3.2.1 on SL.
Best wishes,
Martin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer
Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: email@hidden
WWW: http://www.aei.mpg.de/~hewitson
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden