0

I have two UITableViewCells that looks exactly the same, but each one has a completely different logic. So I want to create two UITableViewCell, with the same xib.

The logic of each cell is different and I don't want to have code split with ifs.

How do I do that?

Gal
  • 1,582
  • 2
  • 14
  • 30

1 Answers1

0

If its a same UI than you shouldn't create two UITableViewCell.

What you can do it write two different updateView method in a same uitableview class.

This way you can reuse the code and also if there is design change you just need to change in one place

Kuntal Gajjar
  • 792
  • 6
  • 12
  • That's not going to solve my problem. – Gal May 09 '18 at 14:08
  • Can you please give some more details of your problem? – Kuntal Gajjar May 09 '18 at 14:12
  • What you're suggesting is to have one class with all the code in it. Exactly what I'm trying to avoid. – Gal May 09 '18 at 14:16
  • You can still create one class and create two different protocols. and you class should confirm that two protocols. This way you can separate your logical part – Kuntal Gajjar May 09 '18 at 14:29
  • Create a protocol for viewModel with a property say valueToBeDisplayed . Create 2 viewModels implementing the above protocol. Say in one cell you want to display firstName and in second cell you want to display lastName. So viewModels can have a property valueToBeDisplayed and assign respective values to respective models. Cells should have a property of this viewModelProtocol. In cellForRowAtIndexPath method assign the viewModel to ur cell. In cell just set the valueToBeDisplayed to your label. – Abhishek729 May 10 '18 at 01:57