A
A
Andrey Myvrenik2017-10-14 11:06:29
iOS
Andrey Myvrenik, 2017-10-14 11:06:29

How to correctly implement "Loading/Content/Error/Empty" controller states in iOS?

Let's say we have a UITableViewController controller added to the Storyboard. In the controller implementation, you can load the data and display it in the cells of this list. But, showing emptiness during data loading, and even more so if an error occurred or there is no data, in a real application, is not an option at all.
Actually, the question is, by what principle or pattern are the various states of the scene implemented:

  • Loading data (loading indicator + "Loading" text)
  • Show data after loading (filled TableView is shown)
  • Error (text + "Retry" button)
  • Emptiness (picture + text indicating that there is currently no data)

In Android, this is solved by creating four separate XML layouts, which are imported into another single XML with a FrameLayout that overlays them. Then in the code, depending on the required state, the visibility of each of the four groups is manipulated (this logic is moved to an abstract class). Thus, it is quite easy to change something if necessary, and you can reuse some of the layouts in other similar "controllers" with a list of loaded data. Is it possible to achieve something similar with all these Storyboards?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Myvrenik, 2017-10-14
@gim0

I found a wonderful StatefulViewController project that solves exactly this problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question