To see if a view has been added to the window, you can override the view viewDidMoveToWindow method and register the [self window] value to check (if it is nil , then the view has been removed from the window)
- (void)viewDidMoveToWindow { NSLog(@"window=%p", [self window]); [super viewDidMoveToWindow]; }
You should be subclassed by NSView , not NSCustomView , and initWithFrame is the designated initializer for NSView , not init .
Try:
TestView *view = [[TestView alloc] initWithFrame:NSMakeRect(0, 0, 100, 200)]; [[_window contentView] addSubview:view];
source share