TableView控制器-Swift

时间:2016-04-06 12:52:01

标签: ios swift uitableview cells

我试图在tableview控制器的单元格中显示一组名称。

以下是代码:

import UIKit

class TableViewController: UITableViewController 
{

    var names = ["aA", "aB", "cC"]

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int
    {
        return 0
    }

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


    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCellWithIdentifier("MyCell", forIndexPath: indexPath)
        cell.detailTextLabel!.text = names[indexPath.row]
        return cell
    }
} 

当我模拟它时,细胞中没有出现任何东西! As in the image here

我的代码有什么问题! 编译器没有给我任何错误。

1 个答案:

答案 0 :(得分:2)

更新部分数量。你的问题将得到解决。

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}