2015-10-05 5 views
0

У меня есть проект Table View Controller Swift в Xcode.Как добавить 2 detailTextLabels в ячейку в Swift?

Я сделал детальTextLabel в течение крайнего срока. Я хотел бы добавить примечания, как это появляется сразу под срок (NSDate) как второй detailTextLabel (NSString), то, как встроенный в напоминание приложение.

Я попытался добавить его, но каждый раз, когда я реализую второй detailTextLabel, крайний срок исчезает и остается только примечаниями под заголовком. Кроме того, я попытался объединить 2 субтитры в detailTextLabel, но он не мог, потому что крайний срок NSDate и нота Строка.

Надеюсь, вы могли бы мне помочь. Спасибо заранее!

Ниже приведены некоторые из моих кодов:

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 
} 

ответ

1

Вы не можете изменить основную ячейку, поскольку она имеет собственный специфический интерфейс. Итак, создайте свой собственный класс ячеек и назначьте его вам в свою ячейку, чтобы вы могли объединить столько ярлыков, сколько хотите. И ваш код немного изменится:

let cell = tableView.dequeueReusableCellWithIdentifier("todoCell", forIndexPath: indexPath) as! YourCellClass 

это все! Надеюсь, поможет.

+0

Вы хотите изменить стиль от подзаголовка до пользовательского и добавить ярлыки? –

+0

Да –