Deathstalker Deathstalker - 1 year ago 165
Objective-C Question

how do i create a custom uiview from a xib

I worked on a project recently where the senior engineer created a custom tab bar. He completely removed the traditional tab bar and replaced it with his own. Looking at the code, I can see that he created the files HOFooterBar.h, HOFooterBar.m, and HOFooterBar.xib. Within the .xib file, he drew out what the footer is supposed to look like in interface builder. He inherited the UIView class. Within the .h file, he created a protocol for the class, so that commands can be taken from actions given within the view. On the main view controller, he simply added a UIView where it belonged, and changed the class to HOFooterBar in the identity inspector.

That's what I can see, but I'm trying to reproduce the results in my own code and it's not working. The UIView i add to my view controller just shows up white. At one point, I added the UIView to my code manually (without IB) and it worked. But i need to be able to add it from interface builder. Any ideas how to make this happen, and why it isn't working for me? I'm open to more questions if i wasnt clear enough

Answer Source

So once you have your custom view written (make sure it inherits from UIView) You can go to your main xib, and on the bottom right make sure you have the object selected (cube thing), and search for custom view. From there, you can drag that custom view into your main view-- and then in the identity inspector assign that custom view to be an instance of your custom view class.

If the contents of the custom view are being created programmatically (which is what it sounds like your senior engineer friend did in his header/implementation files), then the custom view will show up being empty in your xib, and during runtime the custom view will populate with what was given to it programmatically.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download