user979331
user979331

Reputation: 11911

Swift 4 UITableView Like Apple Music Search

I am using UITableViewController and I am playing an having multiple sections to my UITableViewController, I am just curious how do I get headings like Apple Music Search, see screenshot below:

enter image description here

I am talking about the 'Recent' and 'Trending' headings, are those just the section headings or multiple tables?

Upvotes: 0

Views: 410

Answers (1)

Maihan Nijat
Maihan Nijat

Reputation: 9355

Use built-in iOS table view section headers. Place your titles in the collection/ array and display it as follows:

let titles = ["Section 1", "Section 2", "Section 3"]

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return titles[Int]
}

Also, you need to define number of sections:

func numberOfSections(in tableView: UITableView) -> Int {
    return titles.count
}

Upvotes: 1

Related Questions