0

I see this called ALL THE TIME on iOS, and it makes it very hard to port some of the cool Core Abimation stuff out there to the Mac, cause I can't figure out what the following is for...

-(void)willMoveToSuperview:(UIView *)newSuperview {

TwUI (Twitter's Mac GUI framework) has a similar / identical method in their TUIView class, - (void)willMoveToSuperview:(TUIView *)newSuperview {}, which is a method to Create a new Instance of @interface TUIView : TUIResponder subclass. This leads me to believe it is a general call to create a new instance of NSResponder?, which I admit is one of the Cocoa Patterns I understand least… I had sort of thought it might be a call just to unload the View, or to load a new view, or maybe to change the view heirarchy.. But again, not sure.

Regardless… is there is a straightforward / equivalent call on the Mac side, or is this a different beast, due to the fundamental differences in the View Controller structure between AppKit/UIKit?

Alex Gray
  • 16,007
  • 9
  • 96
  • 118

1 Answers1

3

You can override -[NSView viewWillMoveToSuperview:] in a custom NSView subclass. This is simply a means for your class to be notified when its position in the view hierarchy is about to change. It doesn't have some deeper meaning other than what its name implies, but you can, of course, harness it to serve various purposes. It's not a method on a delegate or on the view controller, but you can implement such delegation yourself if you want.

Also, if your code is moving views around the view hierarchy, it can directly do whatever it wants immediately beforehand, which is also roughly when such a method would be called.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154