开发者

Return values from a sheet?

In my application I open a sheet window for user input. Because the window is complex and has a few textfields and a few buttons I created a separate controll开发者_如何学JAVAer for it (InputWindowController).

When the sheet is closed I want to receive some values from the InputWindowController but I don't know how. In all samples I found the controls in the sheet are connected to Outlets in the main controller but that is not what I want. If I do like that I don't need a separate controller.

Also I am not exactly sure what the ContextInfo is for. You can set it right before the sheet should open and you can receive it when it is closed. If I could change the contextInfo in the sheet while it is open it really would help a lot.


When the sheet is closed I want to receive some values from the InputWindowController but I don't know how.

Give the InputWindowController a property for a delegate, and a protocol specifying the method that that delegate must implement. Have that method be the way that the InputWindowController communicates the end of the sheet back to the object that wanted to run the sheet.

I would suggest making a model object that holds whatever values are displayed and editable in the sheet. Give the InputWindowController a property by which to hold one such model object. Then, when the object that wanted to run the sheet receives the InputWindowController's notification that the sheet has ended, the object that wanted to run the sheet asks the InputWindowController for the model object.

Alternatively, the object that wants to run the sheet can set up key-value observing on the model object before invoking the InputWindowController. That way, it will receive (and be able to save and make undoable) those changes to the model object's properties as they happen; then, there is nothing further to do at the end of the sheet.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜