没有内容的tableview单元格

时间:2015-12-24 06:15:26

标签: ios arrays swift uitableview

我的表格视图正在填充,但没有关于单元格的内容 当我试图把这行//cell.textLabel?.text = todoItems[indexPath.row]。我收到此错误check the error

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

3 个答案:

答案 0 :(得分:0)

你可以找到todoItems的类[indexPath.row]是DataSource

print(todoItems[indexPath.row].classForCoder)

cell.textLabel?.text的类是String。 所以你指定了错误的类型。你应该这样做:

cell.textLabel?.text = todoItems[indexPath.row].itenName

答案 1 :(得分:-1)

您指定了错误的类型。你应该这样做:

let item = todoItems[indexPath.row]
cell.textLabel?.text = item.itenName

答案 2 :(得分:-1)

你应该这样做

let item = todoItems[indexPath.row] as DataSource
cell.textLabel?.text = item[indexPath.row].itenName