I have tableView that populates multiple cells. In one of the cell I want to populate 'xib1', if I have data in my array. But if I have 'nil' in my array I want to populate 'xib2' in the same tableview instead of 'xib1'.
How shall I achieve this behaviour in Swift.
I tried using condition say, if the array is nil show xib2 and if not show xib1. Didnt work. it loops in 2nd condition and keeps showing that data where as I want it to show rest of the cells as well which dont have any such conditions.
While the question describes displaying different .xib files conditionally dependent on the array's contents, it is much simpler to create two different subclasses of UITableViewCell, each with its own associated .xib, and then register both subclasses of cell for your table. This is what Duncan C is referring to in his comment.
If you do this, determining which cell to display in the
cellForRowAtmethod becomes very straightforward: just do a test for nil at the corresponding array index, and return a different cell based on the result. Below is a minimal example of this, which I've tested and confirmed works:VIEW CONTROLLER CODE
FIRST CELL (for non-nil array items)
SECOND CELL (for nil array items)
And here are the two .xib files (the text on the green one changes to reflect the value from the array):