-1

I have an application with two windows, the main window opens the second window that is a NSWindowController and in its xib file there is a custom view, is there any way to draw in this custom view from NSWindowController?

thanks

2 Answers2

0

Override - (void) drawRect:(NSRect) dirtyRect in your custom NSView to do the drawing.

If you need to inform this drawRect method from your (custom) NSWindowController, you can use delegate or data source patterns by setting an outlet from the view to the NSWindowController.

DDP
  • 2,463
  • 1
  • 26
  • 28
  • Not an example but this question discusses the two approaches- https://stackoverflow.com/q/2232147/3342547 – DDP Dec 08 '17 at 18:07
0

solved, I have declared two IBOutlets, one on NSView:

IBOutlet MyNSWindowController *wc;

and one on NSWindowController:

IBOutlet MyNSView *view;

then, I have to connected them to custom view.

Now I can to use its methods simply calling its IBOutlets.

  • Note that it is not a good idea to create an outlet from one window `A` to another window `B`'s view in principle -- they are supposed to exist, move, and be released independently, and they will. So the foreign outlet to `B`'s view can become nil any time for reasons outside window `A`' s control. Be careful; and consider creating a different kind of cross-connection between both windows, perhaps using a delegate that knows both window controllers. – ctietze Dec 13 '17 at 12:34