4

I have the only cell template for items at two different UITableViewControllers/TableViews. What I need is to define it once and then reuse at other UITableView via

UITableView.DequeueReusableCell(CellId);

The issue is that is when I call this method on UITableView which doesn't contain cell prototype I'm getting NULL.

How to reuse my prototyped cell across multiple table controllers? I want to define cell template in storyboard, NOT xib.

Mando
  • 11,414
  • 17
  • 86
  • 167

3 Answers3

4

It turned out that the only way to reuse a cell it to design it with xib and register at tableview that xib with cellid.

Mando
  • 11,414
  • 17
  • 86
  • 167
0

Just copy-paste your prototype cell in every table view controller where you need it.

And if I understand your question, in a standard and proper way, it's not possible to dequeue a cell from another table view, Apple implementation handles this mechanism itself.

sweepy_
  • 1,333
  • 1
  • 9
  • 28
  • so my only option is to design it as separate XIB? – Mando Jun 12 '14 at 18:28
  • 1
    No, you can do it directly in your storyboard file. Drag-n-drop a cell prototype, make it an instance of your custom class, and add some elements as subviews from the bottom right menu. – sweepy_ Jun 12 '14 at 19:08
  • 1
    I mean without copy/paste. Copy/paste it is the last thing I will try – Mando Jun 12 '14 at 19:31
  • No I don't know any other way to do that. Actually this is even really useful: for the same kind of cell and without changing one line of code, you can arrange elements another way from one controller to another one. – sweepy_ Jun 12 '14 at 19:44
0

Using xib for a reusable cell is beneficial while cell design is fixed in the whole app. But when there are conditional requirements or slight changes in design or functionality and remaining design and functionality is same for tableview cell, in this case if you still want to reuse the code then you can subclass tableview cell class.

Pramod More
  • 1,220
  • 2
  • 22
  • 51