开发者

Sharing NSDocument subclass between multiple NSWindowControllers

I have a application that isn't currently a document-based application (because I thought it would be more trouble than its worth). However I've been thinking it may possibly be worth it now, but there is one issue I haven't worked out yet. Sharing NSDocument subclasses between multiple windows.

So do subclasses of NSDocument have to be tied to a single NSWindowController, or can I share these between multiple windows? The reason I ask is my applications files are likely to up 100MiB (or larger) and its also likely that a user will open the same file in more than one window. Also these files take a relatively long time to process, so allowing multiple windows access to the same NSDocument would be excel开发者_开发问答lent. Also, the files are updated very quickly with lots of data, so synchronizing multiple instances of the same document would use a lot of CPU time.

Has anybody done this, or can it even be done with a Document-based application? Any advice on this topic is greatly appreciated.


You should be able to use the method - (void)addWindowController:(NSWindowController *)aController found in the NSDocument Class Reference to do just that. There will be a lot of logic to let it know where to send what data, but this will at least give you control over several window controllers linked to the same document


So far this is the best answer I've found, which doesn't directly answer the question, but deals with many of the same obstacles I'm facing. Hopefully someone else has a better, more detailed and direct answer for me.

http://www.cocoadev.com/index.pl?DocumentBasedAppWithOneWindowForAllDocuments


The Document architecture wil help you to manage multiple models - ie. if you want the user to have multiple models open simultaneously and be able to switch between them, it could be of benefit to you.

It doesn't stop you from doing anything, it doesn't make otherwise easy things difficult. Handling the Windows and GUI is still down to you, and if you are unsure how to structure this, it wont make any difference if you use a document or not.

If the contents of a window can change over time to represent different documents - what happens when many documents are open? This can be a difficult problem to solve, and i don't really mean from a technical point of view (changing a window's contents is as easy as window.contentView=newView, right?).

It sounds like you have many misconceptions about what the document architecture is and what it can do for you.


The default is each document has one dedicated windows controller. But you can override

- (void)makeWindowControllers

to create your own windows controller and add them to the document as Slev mentioned.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜