Diferdin Diferdin - 13 days ago 6
iOS Question

Dynamically changing cell type on a table

I have tried to google for hints on this problem but haven't found anyone suitable.
I'm in a scenario where I need to change the type of cells in a table based on whether the user has authenticated or not. Specifically: the user executes the app and the landing page is the table. In it, each cell (of type, say, STANDARD_CELL) subscribes to a (very frequently changing) source of information and starts getting data. In order to login, then, the user leaves the screen with the table and lands on another screen where he/she can provide credentials. Upon authentication, the user should be able to go back to the previous table and this should now have a different type (say, TRADE_CELL).
My trouble is that this does not seem to happen and cell type stays the same as the first load.

Any suggestion on how to fix this?

Answer

Make sure you're checking the status of your authentication in tableView:cellForRowAtIndexPath: in order to serve up the right type and that when transitioning to authenticated or unauthenticated you call reloadData on your tableview.

Comments