Dynamically loading part of a window in Cocoa

I have a window area (in my MainMenu.xib) that I would like to dynamically populate with unrelated β€œviews” such as NSTable, IKImageBrowserView, etc. at different points in time, depending on some criteria selected by the user.

  • How to define this area of ​​the window so that it can be "replaced" with different views?
  • How to attach a table or other view to this area of ​​the window?

(is it enough to post a generic NSView there and add a subview every time? I'm new to Cocoa, so any pointers are welcome)

+3
source share
3 answers

Cocoa . (1, 2, 3) , NSViewController.

+6

. " nsview" windowDidLoad. :

@interface MyController : NSWindowController
{
    IBOutlet NSView* dummyView;
}
@end

@implementation MyController
-(void)windowDidLoad{
    NSView* actualView = ...; //create the real view here
    [actualView setFrame:[dummyView frame]];
    [actualView setAutoresizingMask:[dummyView autoresizingMask]];

    NSView* superview = [dummyView superview];
    [dummyView removeFromSuperview];
    [superview addSubview:actualView];

    dummyView = actualView; //just incase dummyView is ever used again
}
@end
+1

2 2. , topView bottomView , . :

addSubview ( , uiview )

, , :

[topView addSubview:roundedUIButton_instance];

[topView addSubview:another_view_instance];

removeFromSuperview (is a function of the objects used to remove it itself)

[roundedUIButton_instance removeFromSuperview];

OR

[another_view_instance removeFromSuperview];
0
source

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


All Articles