NSOulineView scroll position

Discussion in 'Mac Programming' started by BollywooD, Aug 12, 2009.

  1. BollywooD macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #1
    I have an NSOutlineView, that when reloaded - always reloads to the scroll position declared in my awakeFromNib. I would like to reload it to the same scroll position before it was reloaded.

    How can I do this.....

    thanks in advance.
    :confused:
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Not sure I understand the question exactly, but you can set the scroll position through a variety of ways. Easiest might be to use NSTableView's scrollRowToVisible: method.
     
  3. BollywooD thread starter macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #3
    Ill give that a try, after dinner.

    thanks.

    just to clarify a bit, the NSOutlineView is bound to an NSTreeController, which reloads itself every-time the data changes. (the data is the NSHTTPCookiesStorage, which changes often)

    when the NSOutline view does reload, it reloads with the last selectedObject focused, I would like it to reload to where the view was - regardless of where the last selectedObject is inside the NSOutlineView.

    I hope that makes some kind of sense....
     
  4. BollywooD thread starter macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #4
    Is there a method which outputs - which rows are visible at any given time in the OutlineView?
     
  5. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #5
    I don't see anything directly, but with a combination of the visibleRect and rowsInRect: methods you could probably do what you want. You might have to override NSArrayController to customize the behavior though.
     
  6. BollywooD thread starter macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #6
    Ive been playing around with rowAtPoint, but cant make it work. ill try your suggestions.

    thanks
     
  7. BollywooD thread starter macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #7
    I used to following code, which works reasonably well....

    there is a slight jump, to the closest available row - which is better than what i had before....

    Code:
    NSRange rowRange = [myOutlineView rowsInRect:[myOutlineView visibleRect]];
    	
    	int row = (NSMaxRange(rowRange));
    	int newRow = (row - 1);
    		
    /////reload myOutlineView
    	
    	[myOutlineView scrollRowToVisible:newRow];
    itd be nice if I could eliminate that small 'jump' also.
     
  8. BollywooD thread starter macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #8
    I found this code in Apple's documents (go figure)

    Code:
    	
    //get current scroll position
    NSPoint currentScrollPosition = [[myScrollView contentView] bounds].origin;
    		
    //reload OutlineView/ScrollView	
    
    //restore scroll position
    [[myScrollView documentView] scrollPoint:currentScrollPosition];
    it does exactly what I need.
     

Share This Page