[英]tableview cell with no content
當我嘗試放置此行//cell.textLabel?.text = todoItems[indexPath.row]
時,我的表格視圖正在填充但單元格上沒有內容。 我收到此錯誤檢查錯誤
// Cell creation
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TableViewCell
cell.selectionStyle = .None
let item = todoItems[indexPath.row]
cell.delegate = self
cell.toDoItem = item
// modify the cell to have check mark
if (item.completed) {
cell.accessoryType = UITableViewCellAccessoryType.Checkmark
}
else {
cell.accessoryType = UITableViewCellAccessoryType.None
}
return cell
}
// Data source
class DataSource: NSObject {
let itenName: String
var completed : Bool
var deadline : NSDate
var UUID :String
init(itenName :String , completed :Bool = false , deadline : NSDate , UUID :String ) {
self.itenName = itenName
self.completed = completed
self.UUID = UUID
self.deadline = deadline
//self.subTitle = subTitle
}
}
你可以發現 todoItems[indexPath.row] 的類是DataSource
print(todoItems[indexPath.row].classForCoder)
而 cell.textLabel?.text 的類是String
。 所以你分配了錯誤的類型。 你應該這樣做:
cell.textLabel?.text = todoItems[indexPath.row].itenName
您分配了錯誤的類型。 你應該這樣做:
let item = todoItems[indexPath.row]
cell.textLabel?.text = item.itenName
你應該這樣做
let item = todoItems[indexPath.row] as DataSource
cell.textLabel?.text = item[indexPath.row].itenName
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.