我創建了一個包含 Sqlite 資料庫欄位的檔案,但我無法從 tableView 訪問屬性
DataTableWord.swift
class DataTableWord{
var idWord: Int = 0
var word: String = ""
var features: String = ""
var number: Int = 0
init(idWord: Int, word: String, features: String, number: Int) {
self.idWord = idWord
self.word = word
self.features = features
self.number = number
}
}
ViewController.swift
import UIKit
class ViewController: UIViewController, UITextViewDelegate, UITableViewDataSource {
var dataTableWord: [DataTableWord] = []
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataTableWord.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "idCell1Main1", for: indexPath) as! TableViewCell
cell.cellLabelNumber.text = dataTableWord.[indexPath.row].idWord
return cell
}
}
為什么這個錯誤資訊?

uj5u.com熱心網友回復:
型別idWordis Intbutcell.cellLabelNumber.text是 string 。你不能均衡這兩種不同的型別。
改變
cell.cellLabelNumber.text = dataTableWord[indexPath.row].idWord
和:
cell.cellLabelNumber.text = "\(dataTableWord[indexPath.row].idWord)"
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/416282.html
標籤:
