TableView在执行时不可见

时间:2018-01-05 22:50:39

标签: ios swift uitableview

这个问题已在这里被问了好几次,但它们似乎没有解决我的问题。

我正在运行Swift 4,我有一个TableView连线来查看控制器。

datasource and Delegate wired to the view

以下是我在ViewController.Swift中的代码。

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    let dailyTasks = ["Check all windows","Check all doors", "Check temparature of freezer", "check mailbox at end of the lane", "Empty trash containers",
                      "if freezing then check water pipes outside"]

    let weeklyTasks = ["check inside all unoccupied cabins", "Run all faucets for 30 seconds", "Walk the perimeter of property", "Arrange for dumpster pickup"]

    let twoWeektasks = ["Run test on security alarm", "Check all motion detectors", "Check smoke alarms"]

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

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        switch section {
        case 0:
            return dailyTasks.count
        case 1 :
            return weeklyTasks.count
        case 2 :
            return twoWeektasks.count
        default:
            return 0
        }
    }

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

        var currenTask: String
        switch indexPath.section {
        case 0:
               currenTask =    dailyTasks[indexPath.row]

        case 1: currenTask  = weeklyTasks [indexPath.row]

        case 2: currenTask  = twoWeektasks[indexPath.row]

        default:
             currenTask  = ""

        }

        cell.textLabel!.text = currenTask
        return cell
    }

    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        switch section {
        case 0:
            return "dailyTasks"
        case 1:
            return "weeklyTasks"
        case 2:
            return "twoWeektasks"
        default:
            return ""
        }
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         print ("You selected row \(indexPath.row) in section \(indexPath.section)")
    }
}

然而,当我运行程序时,我看到一个空视图。谁能让我知道我错过了什么?

0 个答案:

没有答案