我试图在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
}
}
我的代码有什么问题! 编译器没有给我任何错误。
答案 0 :(得分:2)
更新部分数量。你的问题将得到解决。
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}