3

I am making a layout similar to this layout of view

Here all cells are different UI (approx 9 cells). So I tried using XIB files for each one and added in

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
{
}

But using xib i have achieved UI but i am finding it complicated.

Please guide me how can i achieve this layout, if there is any better solution than XIB.

And if any of this cell has to be reused in Other ViewController, how to design and code it to avoid repeating.

niravdesai21
  • 4,818
  • 3
  • 22
  • 33
  • You added all of these as section headers??? – Simon McLoughlin Aug 17 '16 at 15:04
  • Yes, but i feel its not appropriate, so asked it here. – niravdesai21 Aug 17 '16 at 15:06
  • No its not appropriate, they need to be cells inside sections, not all section headers. There are many many many tutorials online about creating prototype cells and reusing them as required, do some research online first. – Simon McLoughlin Aug 17 '16 at 15:09
  • Yes ok but if i want any one this cell to be reused in another view controller, should i redesign there? – niravdesai21 Aug 17 '16 at 15:13
  • If cells are being reused across viewControllers then they should be made into .xib's. However having a cell inside an .xib doesn't mean it has to be inside a section header. Again google how to reuse UITableViewCells across viewControllers. Their are hundreds on answers on this site alone – Simon McLoughlin Aug 17 '16 at 15:16
  • Ok thank you very much i will learn on this – niravdesai21 Aug 17 '16 at 15:18
  • Possible duplicate of [In a storyboard, how do I make a custom cell for use with multiple controllers?](http://stackoverflow.com/questions/9245969/in-a-storyboard-how-do-i-make-a-custom-cell-for-use-with-multiple-controllers) – Simon McLoughlin Aug 17 '16 at 15:19

1 Answers1

1

What you could do is make different cells and then when you call the cellForRowAtIndexPath you can load in a different cell depending on the index you are at. For example, at index 3 you may want to load in cell A while at index 5-7 you may want cell C.

Just go to the tableview drop in the cells you need, design each one, link it with a class, and then set its reuse identifier. Don't add them as section headers but as prototype cells.

Jonah Starling
  • 539
  • 6
  • 20