Scrolling problem...

  • I've having the darnedest time with an NSScrollView that I'm using to
    display a large view.

    I'm taking the contentView from an offscreen window and setting it as
    the content view of the NSScrollView. When it comes up on the screen,
    the horizontal scroll bar is all the way to the left, but the vertical
    scroll bar is at the bottom. It needs to be at the top, so I tried
    scrolling with scrollRectToVisible. Here is my code with some debugging
    statements:

    - (void)windowDidLoad
    {

    NKDInvoiceController *ctrl = [[NKDInvoiceController alloc]
    initWithInvoice:[self invoice]
                    andProject:[self project]];
    NSView *contentView = [[ctrl window] contentView];
    NSLog(@"contentView: %@", contentView);
    [scrollView setDocumentView:contentView];

    BOOL didScroll = [scrollView scrollRectToVisible:NSMakeRect(0,
    ([contentView frame].size.height - 5), 5, 5)];
    NSLog(@"documentView height: %f", [contentView frame].size.height);
    NSLog(@"didScroll: %@", didScroll ? @"YES" : @"NO");

    [ctrl release];
    }

    The result of this is the following:

    2003-01-23 11:41:14.152 SimpleInvoicer[1754] contentView: <NSView:
    0x146be60>
    2003-01-23 11:41:14.155 SimpleInvoicer[1754] documentView height:
    666.000000
    2003-01-23 11:41:14.155 SimpleInvoicer[1754] didScroll: NO

    I can't figure out why it's not working. I'm defining a rectangle in
    the upper left corner and telling it to scroll until that Rect is
    visible, but it's not working. I've tried a bunch of different ways to
    get it to display the way I want it and nothing's working. I had
    thought that maybe my origin was inverted, but I also tried with
    NSMakeRect(0,0,5,5) and the results were the same. Anyone have any
    thoughts on what I'm doing wrong?

    TIA
    Jeff
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On Friday, January 24, 2003, at 12:01  AM,
    <cocoa-dev-request...> wrote:

    > BOOL didScroll = [scrollView scrollRectToVisible:NSMakeRect(0,
    > ([contentView frame].size.height - 5), 5, 5)];

    You should be calling scrollRectToVisible on the document view instead
    of the scroll view.

    --
    Brian Webster
    <bwebster...>
    http://homepage.mac.com/bwebster
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month january 2003 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today