ios - 原型(prototype)单元格未显示在 UITableView 中

标签 ios uitableview swift

这是我的代码:

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/

相关文章:

ios - 当我编译 `GLSL` 代码时,出现错误 'ERROR: 0:15: ' premature EOF' : syntax error syntax error'

ios - 委托(delegate)在使用协议(protocol)时得到 nil

swift - 使用 stackview 使 UITableView 下拉

ios - 在 ParallaxBlur Controller 中刷新 TableView

closures - 在 Swift 中调度闭包表达式

ios - 未从 UITableViewCell 调用委托(delegate)方法

ios - 尝试使用QLPreviewController预览大文件时出现问题

ios - 带有 && 运算符的 If 语句检查第二个值?

ios - UITableView 中缺少 UINavigationBar

ios - 知道 SKLabelNode 中文本宽度的方法