簡體   English   中英

原型單元格未顯示在UITableView中

[英]Prototype cells not showing up in UITableView

這是我的代碼:

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!
    }
}

一切都應該如此,但是表視圖只是顯示多行而沒有任何文本。

我究竟做錯了什么?

在情節提要中選擇tableView控制器,單擊身份檢查器右側欄上的第三個,最頂部是“自定義類”。

您好像忘記了鏈接它們,您的班級名稱

class ViewController: UITableViewController {...}

應該在此處輸入,因此只需鍵入“ ViewController”,它應該自動完成。 應該是您所需要的。

我知道它已經很晚了,但是2017年任何人仍然會盡力解決這個問題,請確保您使用的是Interface Builder中正確的“ identifier”字段來提供可重復使用的標識符。 接口構建器具有“可訪問性標識符”和“可重用標識符”,它們在接口構建器中都方便地標記為“標識符”,很容易混淆。

看截圖: 在此處輸入圖片說明

可訪問性標識符與原型單元無關-它與為需要可訪問性功能的用戶提供有用的信息(例如,語音協助)有關,請參閱下面的鏈接以獲取更多信息: 使您的iOS應用可訪問

您是否已將標識符添加到表格視圖中的單元格“ SlopesCell”,並且還將表格視圖控制器的類設置為“ ViewController”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM