Search code examples
iosswiftuikit

Advantages of tableView vs. creating UI elements in code?


I have a feature that allows users to tap the side of the screen to go through content (like instagram stories). The information is presented in different formats: example of screen types

Currently, I am just creating UI elements (through CGRect) and placing the content on the screen according to the template type that comes in. There are many screen types and the canvas has to repaint with each switch. Should I be utilizing tableView for speed (development or otherwise)? Repainting on condition

Is this bad practice to constantly reload and recreate items with each tap?


Solution

  • A table view is a vertically scrolling sequence of "cells" and has nothing in common with the situation you are describing, as far as I can see.

    Actually what you are describing might be a UIPageViewController, which lets you "page" through entire screens of material and yet create each "page" dynamically according to what comes "next" in the series.

    Each page would be its own view controller and could configure its own views. There would be no subviews to remove; rather, the "next" view is just sitting there waiting to be asked for. Each time the user changes the "page", the old screenful of views just goes away after sliding off the screen.