Home > Enterprise >  Swift UITableView with multiple columns
Swift UITableView with multiple columns

Time:09-27

I'm trying to create a UITableView with multiple columns to display standings for football leagues. I have already tried creating it using multiple UITableViews (shown in the screenshot below).

Has anyone got suggestions for another approach?

UITableView Storyboard

UITableview in the simulator

CodePudding user response:

My approach to this problem would be to have a model like:

struct TeamScoring {
    let teamName: String
    let scores: [String]
}

Then you create a TeamScoring for each team.

Regarding the view, only a single UITableView is needed. You have to create a UITableViewCell that contains labels for all the values.

In the implementation of the following delegate method, for each index you have to pass a model to the corresponding cell:

func tableView(
    _ tableView: UITableView,
    cellForRowAt indexPath: IndexPath
) -> UITableViewCell
  • Related