I have been searching everywhere and nothing so far has worked for me.
Basically I want to have a .xib file called rootView.xib and inside it I want to have a UIView (lets call it containerView) that takes up only half of the screen (so there would be the regular view and a new view). Then I want a different .xib file called firstView.xib and load it inside of containerView. So I can have a bunch of stuff on firstView.xib and a bunch of different stuff in rootView.xib and load my firstView.xib inside of containerView in rootView.xib but since it only takes up half of the screen you would still see the stuff on rootView.xib
[Swift Implementation]
Universal way of loading view from xib:
Example:
Implementation:
For swift 3 & 4
To get an object from a xib file programatically you can use:
[[NSBundle mainBundle] loadNibNamed:@"MyXibName" owner:self options:nil]
which returns an array of the top level objects in the xib.So, you could do something like this:
You could try:
Create a XIB file :
make sure check mark "also create XIB file"
I would like to perform with
tableview
so I choosed subclassUITableViewCell
you can choose as your requerment
XIB file desing as your wish (RestaurantTableViewCell.xib)
we need to grab the row height to set table each row hegiht
Now! need to huck them swift file . i am hucked the
restaurantPhoto
andrestaurantName
you can huck all of you .Now adding a UITableView
name
The name of the nib file, which need not include the .nib extension.
owner
The object to assign as the nib’s File's Owner object.
options
A dictionary containing the options to use when opening the nib file.
first if you do not define first then grabing all view .. so you need to grab one view inside that set
frist
.here is table view controller Full code
you done :)
I created a sample project on github to load a UIView from a .xib file inside another .xib file. Or you can do it programmatically.
This is good for little widgets you want to reuse on different UIViewController objects.