当我运行程序时,模拟器仅显示“人”部分,而不显示“视频”部分

时间:2019-07-10 11:06:12

标签: swift xcode8

您好,我是编码的新手,我想在模拟器上显示一些信息,但是不幸的是,当我运行该程序时,模拟器仅显示程序的人员部分,而不显示视频部分

class ViewController: UIViewController, UITableViewDataSource {

    let people = [
        ("Bucky Roberts", "New York"),
        ("Lisa Tucker", "Alabama"),
        ("Emma Hotpocket", "Texas")

    ]

    let videos = [
        ("Andriod App Development", "74 videos"),
        ("C++ for Beginners", "87 videos"),
        ("Java", "142 videos"),
        ("Python Programming", "63 videos"),
        ("Web Design", "68 videos")

    ]
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3
    }

    func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int {
        if index == 0{
        return people.count
        }else{
            return videos.count
        }
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = UITableViewCell()

        if indexPath.section == 0{
            var (personName, personLocation) = people[indexPath.row]
            cell.textLabel?.text = personName
        }else{
            var (videoTitle, videoDesc) = videos[indexPath.row]
            cell.textLabel?.text = videoTitle
        }
        return cell
    }
    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        if section == 0{
            return "People"
        }else{
            return "Videos"
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
}

1 个答案:

答案 0 :(得分:1)

numberOfSections添加到您的tableView

func numberOfSections(in tableView: UITableView) -> Int {

    return 2 // for people and videos

}