Re: Large over 100K pixel high ruler scroll view
Re: Large over 100K pixel high ruler scroll view
- Subject: Re: Large over 100K pixel high ruler scroll view
- From: Graham Cox <email@hidden>
- Date: Tue, 30 Aug 2011 15:39:01 +1000
On 30/08/2011, at 12:54 PM, Julie Porter wrote:
> I already have the NSDocument.m which loads the array of dictionaries from the file. Do I place the awakefrom nib in that set of class files, or would they go into the file that I would derive from NSView called cisView.m?
>
> Do I need to set up accessors between the myDocument and cisView class files or do they inherit from each other?
NSDocument and NSView are totally unrelated classes.
This seems rather a basic conceptual area you need to understand. Model-View-Controller or MVC (I'm needing to write this in a very skeletal way because I have to be somewhere else imminently - maybe someone else can take a bit more time here).
NSDocument is your model. It manages the file on disk. The View is contained by a window which is controlled by a window controller which is owned by the document. So they're connected, but have very different roles.
You need to set up accessors if your view needs to know about your document, and vice versa. Outlets are an easy solution because you can connect them in IB and they'll be set up for you. However, purists might consider this a violation of MVC but for a simple scenario (which despite everything, yours is) will probably suffice.
So your view will be doing stuff like:
[myDocument giveMeDataForLinesInRange:linesRange]; // in -drawRect:
and your document will be doing stuff like:
[myView setFrame:theSizeICalculatedFromTheData];
WHEN the document does this is when it reads the file in response to a 'Open' commend - you'll find out how to respond to that properly in the NSDocument documentation. This would be instead of the view's -awakeFromNib - that's a good place if you were just setting the frame size to some large fixed number, but since the actual size really depends on the data in your file, then obviously a better place is when you open that file. At this point, NSDocument is preparing the window and its views from the nib, so they're not yet visible. The file opens, the view size is set (you may need to temporarily store the size, and wait until -windowControllerDidLoadNib: is called to make sure that the window/view is actually there - or do it in the view's -awakeFromNib by querying the document - their are plenty of ways to crack this nut) then the window is shown.
Sorry, gotta go….
-Graham_______________________________________________
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