How to implement the feature of resizing NSTableView created programmatically ? Interface builder should not be used. It should be like click and drag to change the size of the NSTableView. Is it possible? If yes, please help. . . .
Asked
Active
Viewed 973 times
0
-
I am not sure what your question is. Do you want the user of your app to be able to resize the tableview? – sosborn Sep 26 '11 at 08:55
-
@sosburn: Yes. The user should be able to resize it. – Soorya Sep 26 '11 at 08:59
-
Hey Soorya.. how do you want to resize your table.. by dragging the corner of window in which it is contained.. or dragging the border of table itself ? – Devarshi Sep 26 '11 at 10:12
-
Hi Miraaj. By dragging the border of table itself. – Soorya Sep 26 '11 at 10:22
-
Follow this http://stackoverflow.com/questions/2595118/resizing-uitableview-to-fit-content – Dhanunjay Kumar Oct 21 '13 at 05:30
1 Answers
0
I am afraid you need to write a bit of code to make it working. This is how I would do it.
Make a special Resize View that will track the mouse events and call delegate methods providing how the tracking position changes.
- (void)mouseDown:(NSEvent *)theEvent
{
_startPoint = [theEvent locationInWindow];
[_delegate resizingDidStart];
}
- (void)mouseDragged:(NSEvent *)theEvent
{
NSPoint hitPoint = [theEvent locationInWindow];
[_delegate resizeWithDeltaX:(hitPoint.x - _startPoint.x) deltaY:(hitPoint.y - _startPoint.y)];
}
Put this view in the right bottom corner of the Base View. Set the autoresizing mask so this view always stays in the right bottom corner.
Put the table view along with its scroll view on to the Base View. Set autoresizing mask of the scroll view so its size and width are sizeable.
In the delegate of the Resize View process changes in the mouse position and set the frame of the Base View.
- (void)resizingDidStart
{
_initialRect = [_baseView frame];
}
- (void)resizeWithDeltaX:(CGFloat)deltaX deltaY:(CGFloat)deltaY
{
[_baseView setFrame:NSMakeRect(_initialRect.origin.x, _initialRect.origin.y + deltaY, _initialRect.size.width + deltaX, _initialRect.size.height - deltaY)];
}
Of course the scroll view should be under the resize view. You can draw some ind of a handle on the resize view, etc.

Davyd Geyl
- 4,578
- 1
- 28
- 35