UITableView 显示某些行

UITableView show some row

提问人:Telember 提问时间:5/16/2016 最后编辑:Telember 更新时间:5/16/2016 访问量:101

问:

我有一个问题。我的表格显示了一些我不知道为什么的行。它应该显示所有行。UITableViewUIViewController

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
    }
}
iOS UITableView Swift2

评论

0赞 Syed Faraz Haider Zaidi 5/16/2016
单元格高度是否与默认单元格高度不同?
0赞 Ketan Parmar 5/16/2016
您没有在数据源方法中配置数据,那么tableview如何显示数据!cellForRowAtIndexPath
0赞 Jayesh Thanki 5/16/2016
您输入的行数为 20,因此表视图创建 20 行
0赞 Brett Donald 5/16/2016
你的问题不清楚。您需要告诉我们更多关于您的期望。您是否希望看到 20 行,每行都包含“Hollo man”?
1赞 Hardik Shekhat 5/16/2016
请在单元格背景中添加颜色。因此,请确切地看到主要问题,要么您没有设置适当的单元格约束,要么表格视图没有创建 20 行。

答:

1赞 Jack.Right 5/16/2016 #1

如果你想要 20 排的你好男人。(所有行)在单元格中为索引路径处的行添加此行

cell.labelname.text = “你好男人”

评论

0赞 Telember 5/16/2016
我尝试添加let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath)作为!TableViewCell cell.lableName.text = “你好!!” 但它显示得像以前一样
0赞 Jack.Right 5/16/2016
是否定义了单元格类?@Telember
0赞 Telember 5/16/2016
是的,我为 UITableViewCell 创建了一个类并添加了一个标签。当我更改标签的文本时,我的行更改了一个单词,但它显示一些与之前相同的行
0赞 Suric 5/16/2016 #2

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