Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BollywooD

macrumors 6502
Original poster
Apr 27, 2005
372
46
Hamburg
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:
 
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.
 
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....
 
Is there a method which outputs - which rows are visible at any given time in the OutlineView?
 
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.
 
Ive been playing around with rowAtPoint, but cant make it work. ill try your suggestions.

thanks
 
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.