Add UIView to UIViewController

I want to add a “custom” uiview to the uiviewcontroller, this is a custom i view created using xib and its separate from the view controller,

Does anyone know how to add uiview with xib to uiviewcontroller?

Thank you very much in advance

+3
source share
2 answers

Do you mean an additional view, not a view of the main controller? In this case, you can declare a property for the view and manually load the NIB:

@interface Controller {}
@property(retain) IBOutlet UIView *extraView;
@end


- (void) viewDidLoad // or anywhere else
{
    [[NSBundle mainBundle] loadNibNamed:@"extras" owner:self options:nil];
    NSAssert(extraView != nil, @"The extra view failed to load.");
    [[self view] addSubview:extraView];
}

, Controller , extraView. , , NIB ; .

+3

, - UIView.

  • XIB, " XIB" Xcode.
  • " " " " " " (Cmd-4) Controller (, , ) "".
  • , .
  • Ctrl + , , .
  • , Controller.xib.
  • , initWithNibName:@"Controller" bundle:nil. , .

Builder, IB - .

+1
source

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


All Articles