提问人:Telember 提问时间:5/16/2016 最后编辑:Telember 更新时间:5/16/2016 访问量:101
UITableView 显示某些行
UITableView show some row
问:
我有一个问题。我的表格显示了一些我不知道为什么的行。它应该显示所有行。UITableView
UIViewController
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
}
}
答:
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 委托和数据源。 顺便说一句,设置正确的约束。
评论
cellForRowAtIndexPath