Reputation: 59
I have a Table View Controller Swift project in Xcode.
I have made a detailTextLabel for the deadline. I would want to add notes as this to appear immediately under the deadline(NSDate) as a second detailTextLabel(NSString), something like built-in Reminder app.
I tried to add it but every time I implement the second detailTextLabel, the deadline disappears and remains just the notes under the title. Also I tried to merge the 2 subtitles in a detailTextLabel but it couldn't because the deadline is NSDate and note is String.
Below is some of my codes:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("todoCell", forIndexPath: indexPath) // retrieve the prototype cell (subtitle style)
let todoItem = todoItems[indexPath.row] as ToDoItem
cell.textLabel?.text = todoItem.title as String!
if (todoItem.isOverdue) { // the current time is later than the to-do item's deadline
cell.detailTextLabel?.textColor = UIColor.redColor()
} else {
cell.detailTextLabel?.textColor = UIColor.blueColor() // we need to reset this because a cell with red subtitle may be returned by dequeueReusableCellWithIdentifier:indexPath:
}
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "'Due' MMM dd 'at' h:mm a" // example: "Due Jan 01 at 12:00 PM"
cell.detailTextLabel?.text = dateFormatter.stringFromDate(todoItem.deadline)
// When I try to add the detailTextLabel for note the deadline disappears
// cell.detailTextLabel?.text = todoItem.note as String!
return cell
}
Upvotes: 0
Views: 785
Reputation: 2059
You can't change basic cell because it has it's own specific UI. So make your own specific cell class and assign it to you it to your cell so you can join as many labels as you wish. And your code will change a bit:
let cell = tableView.dequeueReusableCellWithIdentifier("todoCell", forIndexPath: indexPath) as! YourCellClass
that is it! Hope it helps.
Upvotes: 1