开发者

Passing data to a specific open NSDocument?

开发者 https://www.devze.com 2023-03-24 13:58 出处:网络
I have been having lots of trouble with this one. I need to have an NSViewController and an NSView pass integer\'s to a specific document. I really want it to pass the data to the document represented

I have been having lots of trouble with this one. I need to have an NSViewController and an NSView pass integer's to a specific document. I really want it to pass the data to the document represented by the key window (I hope that makes sense), but the way I am doing passes the data to all of the open documents.

I am using a document based application, from the Xcode template (Cocoa application with the "Document based application" box checked. Is there any way to do thi开发者_JAVA技巧s?

I did not post my code because it really is too embarrassing. Basically, I have a "getter" method in the NSViewController, but I still have not thought of a good way to pass the data back. I ended up with hundreds of lines of code that are supposed to make the document pull the data back with another "getter" method, but they don't do anything.

Is there any documentation on this?


The key window may not have a document behind it, it is just the window that will receive events first, I think what you may be after is -[NSApplication mainWindow] which you can get the window controller for and from that the document, alternatively you could observer the NSWindowDidBecomeMainNotification to keep track of which window is now main or you could use the method -[NSAppliation orderedDocuments] to get the front document. Personnaly I like the NSNotification but there may be resins you prefer one of the other methods.

0

精彩评论

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