2016-05-16 26 views
0

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

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 
    } 
} 
+0

是你的细胞高度是不是默认的细胞高度? –

+0

您没有在数据源方法'cellForRowAtIndexPath'中配置数据,那么tableview如何显示数据! – Lion

+0

你输入的行数是20,所以表视图创建20行 –

回答

1
如果你想你好的男人在指数路径法20行。(所有行)的行单元格添加此行

cell.labelname.text =“你好

男人“

+0

我尝试添加 let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier,forIndexPath:indexPath)as! TableViewCell cell.lableName.text =“Hello !!” 但它显示像以前的 – Telember

+0

你有没有定义单元类?@Telember –

+0

是的,我为UITableViewCell创建了一个类并添加了一个标签。当我更改标签的文字时,我的行改变了一个单词,但它显示了与之前相同的一行 – Telember

0

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