Is it a best practice to use more than one xib in a view controller for a responsive design?
I’m currently implementing an app that relies heavily on a remote API for its data. One particular view is troubling since the layout depends on the data returned from that API. It is either a product that has a full review and pricing, or a product that we only have limited information on.
The design is responsive to the data. Depending on how much information that is returned, the view has a layout that is much different from the other. Also, there’s a quite a few elements that need to be repositioned depending on text length, etc. I had originally implemented the design nearly all in code, but that became quickly unmaintainable so I offloaded almost all of it to the xib and only use code to reposition elements.
Using more than one xib might be a good solution. When the view loads, the controller performs the API request, then loads the new xib if need be. I’m not sure of what downsides there may be to this approach.
I’m implementing now the client-server app. Layout of the most of views is also depending on data from API. In situation like yours I’ve created several xib files (one for detailed product, one for limited etc.) and depending on server response I’m choosing xib to load. Code sample:
Yo could put all versions of view into one xib. In that case you only change index in nibViews objectAtIndex: