Z.Deri
Z.Deri

Reputation: 19

Swift UITableView with multiple columns

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

Upvotes: 0

Views: 126

Answers (1)

JoseIgnacio
JoseIgnacio

Reputation: 74

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

Upvotes: 1

Related Questions