Lukas
Lukas

Reputation: 2535

Xib file inside another xib

there are some similar posts, but I've searched a lot for the answer, but unluckily i didn't found it.

What i want: I am creating a view using xib file. Let's say it's class is BaseView. In this baseView i have a custom subview e.g it's class is InsideView.

Is it possible that when my baseView awakes from nib, the insideView would automatically create itself from it's xib file?

I would like this behaviour because I would reuse this "insideView" in multiple other views and just change the baseView components.

Thanks for any help and guidance!!

EDIT:

to be more clear I would like to create a view like this:

topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"SDBaseView" owner:nil options:nil];
        for(id currentObject in topLevelObjects){
            if([currentObject isKindOfClass:[SDBaseView class]]) {
                self.headerView = currentObject;
                break;
            }
        }

and after assigning this to headerView, I should already have a BaseView with it's properties loaded, and also the insideView with it's properties loaded. So I could do something like this :

self.headerView.someBaseClassProperty = @"Test";

but also

self.headerView.isnideView.someInsideViewClassProperty = @"Inside Test";

Upvotes: 2

Views: 1189

Answers (1)

Vojtech Vrbka
Vojtech Vrbka

Reputation: 5368

Look at this blog post: Embedding custom-view Nibs in another Nib: Towards the holy grail

It's really easy to implement.

EDIT:

I don't recommend this anymore. With new XCode and IBDesignable it's really easy to create custom classes with NIBs

Upvotes: 2

Related Questions