2015-10-05 101 views
0

我在Xcode中有一個表視圖控制器Swift項目。如何將2個detailTextLabels添加到Swift中的單元格中?

我已經爲截止日期做了一個detailTextLabel。 我想添加註釋,因爲這給截止日期(NSDate的)下立即出現第二detailTextLabel(的NSString),像內置提醒應用

我試着添加它,但每次執行第二個detailTextLabel時,截止日期消失,只剩下標題下的註釋。 此外,我想在一個detailTextLabel合併2個字幕,但它不能因爲截止日期爲的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

你不能改變基本的細胞,因爲它有它自己特定的UI。 因此,請製作您自己的特定單元格類並將其指定給您的單元格,以便您可以根據需要加入任意數量的標籤。而你的代碼會改變一點:

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

這就是它!希望能幫助到你。

+0

你的意思是將字幕的樣式更改爲自定義並添加一些標籤? –

+0

是更改爲自定義 –

相關問題