这是我的代码:
import UIKit
class ViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 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.
}
let transportItems = ["Bus","Helicopter","Truck","Boat","Bicycle","Motorcycle","Plane","Train","Car","Scooter","Cara van"]
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return transportItems.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("SlopesCell") as? UITableViewCell
cell?.textLabel?.text = transportItems[indexPath.row]
return cell!
}
}
一切都是它应该的样子,但表格 View 只显示多行,没有任何文本。
我做错了什么?
最佳答案
在 Storyboard上选择您的tableView Controller ,单击右侧栏的第三个身份检查器,最顶部是“自定义类”。
您似乎忘记将它们链接起来,您的类(class)名称
class ViewController: UITableViewController {...}
应该在此处输入,因此只需输入“ViewController”,它就会自动完成。应该是您所需要的。
关于ios - 原型(prototype)单元格未显示在 UITableView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26368951/