Swift UITableView显示不正确
我试图通过实现我在许多教程中看到的代码来使用UITableView,但在运行它时它不能正常工作。我做错了什么?我向视图中添加了一个单元格,并添加了相应的标识符。 代码如下:Swift UITableView显示不正确,swift,uitableview,Swift,Uitableview,我试图通过实现我在许多教程中看到的代码来使用UITableView,但在运行它时它不能正常工作。我做错了什么?我向视图中添加了一个单元格,并添加了相应的标识符。 代码如下: import UIKit import Firebase class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var ref: DatabaseReference? var data
import UIKit
import Firebase
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var ref: DatabaseReference?
var data = ["m","2","3"]
@IBOutlet weak var tableV: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableV.delegate = self
tableV.dataSource = self
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableV.dequeueReusableCell(withIdentifier: "PostCell")
cell?.textLabel?.text = data[indexPath.row]
return cell!
}
}
及
.
请帮我解决这个问题。你应该用这种方法来纠正错误 更改此项: let cell=tableV.dequeueReusableCellwithIdentifier:PostCell 与: 让cell=tableV.dequeueReusableCellwithIdentifier:PostCell,for:indexPath
您需要检查单元格标识符。此代码看起来不错。你们能告诉我你们在哪里发现问题吗?请检查你们是否在故事板中给了PostCell作为你们的单元标识符。这是什么意思,但当我运行它时它不能正常工作?模型上有3个项目,所有3个项目都正确显示在tableview中;这里有什么问题?点击“它看起来像什么”链接到模拟器的图像。@ParthPatel我看到了模拟器的屏幕截图。有3行带有标签m、2和3。错了吗?