• 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
[A] Resizing a window to show full rows from a table view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[A] Resizing a window to show full rows from a table view


  • Subject: [A] Resizing a window to show full rows from a table view
  • From: Chuck Remes <email@hidden>
  • Date: Mon, 21 Dec 2009 12:39:59 -0600

I searched around but could not find an answer to the problem of enforcing a particular window size so that only "whole" rows are shown in a table view. I have archives of this list going back to 2002 but nothing suitable popped up.

Here's the code in objective-j (Cappuccino framework).

/*
 * Enforce a window size that shows only whole rows instead
 * of the default fractional rows.
 */
- (void)windowDidResize:(CPNotification)notification
{
    var window = [self window],
        superFrame = [window frame],
        tableSize = [scrollView contentSize],
        frameDelta = superFrame.size.height - tableSize.height,
        rowHeight = [theTable rowHeight],
        visibleRows = FLOOR(tableSize.height / rowHeight);

    tableHeight = rowHeight * visibleRows;

    superFrame.size.height = tableHeight + frameDelta;

    [window setFrame:superFrame];
}


Four items of note regarding this code.

1. This should be done in the windowWillResize:toSize delegate method instead of a direct call to setFrame but Cappuccino doesn't support that delegate yet.

2. The line "window = [self window]" should probably be "window = [notification object]" when translating to objective-c but for some reason that isn't working right in Cappuccino.

3. FLOOR is a macro corresponding to whatever is Math.floor in your host language. Adjust accordingly.

4. Computing a frame delta between the table view's visible content size and the window frame gives us the correct behavior even when there are other controls or elements inside the window. Some sample code I saw was tracking the size of specific fields and doing a lot more math just to accomplish this task.

If anyone has an improved methodology, please share.

cr

_______________________________________________

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


  • Prev by Date: Re: Detecting system protected folders.
  • Next by Date: Remember Window and Inspector Positions
  • Previous by thread: Re: Releasing an NSBundle
  • Next by thread: Remember Window and Inspector Positions
  • Index(es):
    • Date
    • Thread