My table view is populating but without a content on the cell when I try to put this line //cell.textLabel?.text = todoItems[indexPath.row]
. I am getting this error 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
}
}
You can find the class of todoItems[indexPath.row] is DataSource
with
print(todoItems[indexPath.row].classForCoder)
And the class of cell.textLabel?.text is String
. So you assign the wrong type. You should do it like this:
cell.textLabel?.text = todoItems[indexPath.row].itenName
You assign wrong type. You should do like this:
let item = todoItems[indexPath.row]
cell.textLabel?.text = item.itenName
You should do like this
let item = todoItems[indexPath.row] as DataSource
cell.textLabel?.text = item[indexPath.row].itenName
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.