簡體   English   中英

將Objective轉換為Swift Table視圖不顯示單元格中的數據

[英]Converting Objective to Swift Table view not displaying the data in the cells

我對Swift還是很缺乏經驗,在轉換基於Objective-C的應用程序時遇到了問題。 大多數應用程序都在工作...包括更改節標題的大小和顏色以及單元格的背景顏色,但我無法顯示單元格的內容(TextView和開關)。 任何解決此問題的建議,將不勝感激。 我將代碼包含在更改背景顏色的位置,這是我懷疑問題所在的位置:

    override func tableView(tableView: UITableView,  cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    //variable type is inferred
    var index = indexPath.row

    NSLog ("index %d",indexPath)

    var cell = tableView.dequeueReusableCellWithIdentifier("CELL") as? UITableViewCell

    if cell == nil {
        cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "CELL")
    }

    //we know that cell is not empty now so we use ! to force unwrapping
    var grayishCyan = colorWithHexString("#9bc2c2")
    var grayishRed = colorWithHexString("#ffc2c2")

    if (indexPath.row == 0 || indexPath.row%2 == 0) {
        cell!.backgroundColor = grayishCyan;
    }
    else {
        cell!.backgroundColor = grayishRed
    }

    return cell!
} // end of cellForRowAtIndexPath

我刪除了cellForRowAtIndexPath函數,並將其替換為willDisplayCell函數

暫無
暫無

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

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