UITableView不显示单元格

时间:2015-02-14 01:33:54

标签: ios uitableview swift xcode6

我正在使用Xcode 6 Swift和故事板来构建IOS应用程序。贝娄是我在File.swift中的内容:

import Foundation

struct December {
    let name : String
}

然后,在我的视图控制器中,我有:

import UIKit

class ViewControllerDecember: UITableViewController {

    var december = [December] ()


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        self.december = [December(name: "1"), December(name: "2"), December(name: "3"), December(name: "4"), December(name: "5"), December(name: "6"), December(name: "7"), December(name: "8"), December(name: "9"), December(name: "10"), December(name: "11"), December(name: "12"), December(name: "13"), December(name: "14"), December(name: "15"), December(name: "16"), December(name: "17"), December(name: "18"), December(name: "19"), December(name: "20"), December(name: "21"), December(name: "22"), December(name: "23"), December(name: "24"), December(name: "25"), December(name: "26"), December(name: "27"), December(name: "28"), December(name: "29"), December(name: "30"), December(name: "31")]

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.december.count
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell

        var de1 : December

        de1 = december[indexPath.row]

        cell.textLabel?.text = de1.name

        return cell


    }
}

当我运行应用程序时,它会显示表格视图但不显示任何单元格数据。我错过了什么?

2 个答案:

答案 0 :(得分:4)

您可能只需要将原型单元标识符设置为“单元格”。

转到故事板,单击您的tableview,单击属性。

通过将原型单元格从0更改为1来为自己提供原型单元格。

单击原型单元格。将'identifier'属性设置为“cell”。

答案 1 :(得分:0)

对我来说,除非你刷屏幕,否则我会因为没有显示tableview而感到困惑。最后我发现缺乏陈述:reloadDate()

Query.FindinBackGround(...)
self.mytableview.reloadDate()