Swift 4 UITableView喜欢Apple Music Search

时间:2018-06-02 03:06:07

标签: ios swift uitableview

我正在使用UITableViewController而我正在为我的UITableViewController播放多个部分,我很好奇我如何获得Apple Music Search等标题,请参阅下面的截图:

enter image description here

我在谈论'最近'和'趋势'标题,那些只是章节标题还是多个表格?

1 个答案:

答案 0 :(得分:1)

使用内置的iOS表格视图部分标题。将标题放在集合/数组中,并按如下所示显示:

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

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

此外,您需要定义部分数量:

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