• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTableView within NSScrollView in code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTableView within NSScrollView in code


  • Subject: NSTableView within NSScrollView in code
  • From: Patrick Mau <email@hidden>
  • Date: Wed, 10 Nov 2010 22:34:49 +0100

Hallo everyone

When I embed an NSTableView in an NScrollView, everything works except
column auto-resizing.

What would trigger automatic column layout whenever the NSScrollView frame
is reduced in size?

I have a custom view that creates a NSScrollView and NSTableView:

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];

    if (self) {
        tableView = [[MyTableView alloc] init];
        scrollView = [[NSScrollView alloc] initWithFrame:frame];

        [tableView setAllowsEmptySelection:YES];
        [tableView setAllowsMultipleSelection:YES];
        [tableView setFocusRingType:NSFocusRingTypeNone];
        [tableView setAllowsColumnResizing:NSTableViewUniformColumnAutoresizingStyle];

        [tableView addTableColumn:[self columnWithIdentifier:@"symbol "andTitle:@"Symbol"]];
        [tableView addTableColumn:[self columnWithIdentifier:@"shares" andTitle:@"Shares"]];
        [tableView addTableColumn:[self columnWithIdentifier:@"quote" andTitle:@"Quote"]];
        [tableView addTableColumn:[self columnWithIdentifier:@"commissions" andTitle:@"Commissions"]];
        [tableView addTableColumn:[self columnWithIdentifier:@"taxes" andTitle:@"Taxes"]];
        [tableView addTableColumn:[self columnWithIdentifier:@"total" andTitle:@"Total"]];

        [scrollView setHasVerticalScroller:YES];
        [scrollView setHasHorizontalScroller:YES];
        [scrollView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
        [scrollView setDocumentView:tableView];

        [self setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
        [self addSubview:scrollView];

        [scrollView release];
        [tableView release];
    }

    return self;
}

As you can see, the NSScrollView is a subview of my custom NSView.
It auto-resizes and has its documentView set to the NSTableView.

I omitted the column creation code, but it does something along these lines:

    [tableColumn setWidth:250.0f];
    [tableColumn setMinWidth:100.0f];
    [tableColumn setMaxWidth:500.0f];
    [tableColumn setResizingMask:NSTableColumnAutoresizingMask|NSTableColumnUserResizingMask];
    [tableColumn setDataCell:dataCell];
    [tableColumn setHeaderCell:headerCell];

The columns are indeed resizeable, contain a valid headerCell and dataCell.
As I said, everything is fine, but the columns do not auto-resize.

Thanks a lot,
Patrick

PS: I will created a sample project if anyone wants me to, but if you
copy the NSView's code into a newly created project with a custom view,
you are nearly done.



_______________________________________________

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

  • Follow-Ups:
    • Re: NSTableView within NSScrollView in code
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: Test for launched from (Apple)Script?
  • Next by Date: Re: Cocoa-dev Digest, Vol 7, Issue 1044
  • Previous by thread: Re: Test for launched from (Apple)Script?
  • Next by thread: Re: NSTableView within NSScrollView in code
  • Index(es):
    • Date
    • Thread