Migrating NSView

Sorry if this was asked before or this is a really dumb question, but I can't figure it out. I have an NSView in my interface and I have subclassed NSView in Xcode. Then, using the identity inspector, I found that my NSView class is a newly created subclass of NSView. The view is drawn fine, but now I need to redraw it to change the line inside the view. I am sure this is due to setNeedsDisplay, but why am I sending a message? I do not have a specific instance of my view in code, since it is in Interface Builder, so what should I do? Again, sorry if this is stupid. I haven't done anything with NSView yet. If you need this, request more information. Thanks!

+4
source share
1 answer

In the subclass of the view manager you have, add ivar with the type of your subclass of NSView . Declare a property on it and mark it as an output.

 // ViewControllerSubclass.h ViewType *myView; @property(readwrite, assign) IBOutlet ViewType *myView; // ViewControllerSubclass.m @synthesize myView; 

Now that you have an outlet, plug it into a view developed through IB. To do this, right-click in IB on a subclass of the view controller (file owner), you should see the output in the list.

Once you do this, you can now send messages to the view in your code.
To mark a view when redrawing is necessary:

 [myView setNeedsDisplay:YES]; 
+7
source

Source: https://habr.com/ru/post/1388361/


All Articles