UITableView显示一些行

时间:2016-05-16 06:28:57

标签: ios uitableview swift2

我在UITableView中遇到UIViewController的问题。我的表格显示了一些我不知道原因的行。它应该显示所有行。

simulator Prototype

class TableViewController: UIViewController,UITableViewDelegate, UITableViewDataSource  {
    let cellIdentifier = "testCell"

    override func viewDidLoad() {
        super.viewDidLoad()
    }

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

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
        return 20
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! TableViewCell
        cell.lableName.text = "Hello man"

    return cell
    }
}

2 个答案:

答案 0 :(得分:1)

如果你想要20行中的hello man。(所有行)在单元格中为索引路径方法的行添加此行

cell.labelname.text =“Hello Man”

答案 1 :(得分:0)

请检查您的tableview委托和数据源。 顺便说一句,设置正确的约束。