繁体   English   中英

没有内容的表格单元格

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM