XIB Embedding in Interface Builder / Embed by Link

Say I created an XIB to view the icons. Then I want to insert several instances of this icon in the container view of another XIB by reference , so if I change the properties / layout in the original XIB icon, the instances in the XIB container view reflect these changes.

Essentially an attachment by reference.

Maybe I'm dense, but, apparently, the default behavior of the Builder interface when dragging a view into a container view is to copy everything, and not refer to the original XIB? And dragging and dropping an instance of the class associated with representing the icon as a container leads to a simple view.

I'm sure there is a way to do this, but I'm damned if I can figure it out. I usually avoid IB like the plague;)

+5
source share
2 answers

There is no way to do this directly in Interface Builder. I needed to do something similar in my last application. What I ended up doing is simply placing the Placeholder View in the place where you want your reference xib, and then in your viewDidLoad or viewWillAppear, etc. You downloaded this xib and placed the loaded view as a child of your placeholder view.

NSArray *views = [[NSBundle mainBundle] loadNibNamed: @"ReferencedView" owner: self options: nil];
UIView *referencedView = (UIView *)[views objectAtIndex:0];
[self.viewPlaceholder addSubview:referencedView];

IBOutlet , IB. , NSArray.

+5

:

, iOs 5 containerView. , XIB. .

ContainerView. XIB, , alloc] init, , .

, ContainerView - segue. , , .

:

- (void)viewDidLoad
{

    [super viewDidLoad];

    PO(self.childViewControllers);
    BGCRListBusinessViewController * theListController= [[BGCRListBusinessViewController alloc]init];
    self.listBusinessViewController = theListController;
    [self addChildViewController:theListController];
...
    for (UIViewController * child in self.childViewControllers) {
        child.view.frame=self.ContainerView.bounds;

    }
    //PO(self.ChangeFilter.BackgroundImage);
    //PO
    //self.ChangeFilter setBackgroundImage:[UIImage imageNamed:@] forState:<#(UIControlState)#>

    [self.ContainerView addSubview:self.listBusinessViewController.view];// initialize'
}

....

childViewControllers. IOS5. , , viewWillAppear, viewWillDisappear, ViewDidThisandThat ViewIamRotatingWillOrDidorWhatever. , .

, IOS4, , WillAppear, viewWillDisappear, ViewDidThisandThat ViewIamRotatingWillOrDidorWhatever .

, viewController ContainerView. ViewWillorDidWhatever.

. . . , , ViewWillorDidWhatever.

childViewControllers. IOS4, , . , ViewWillorDidWhatever.

, , - . , .

, . . . . IOS ​​ modalViewController.

0

All Articles