2014-10-12 63 views
1

我在應用程序中添加了一項功能,允許用戶添加筆記,當它們展開以顯示更多內容時,筆記會在表格視圖單元格中顯示。在故事板中設計點擊展開單元格

我的問題是 - 如何佈局單元格展開時要顯示的內容?我曾嘗試將textView添加到原型單元格中,但我只是將textView與表格視圖中的其他單元格重疊,而不是在輕敲之前隱藏。

這是我當細胞被竊聽代碼:

var selectedRowIndex: NSIndexPath = NSIndexPath(forRow: -1, inSection: 0) 

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    selectedRowIndex = indexPath 
    tableView.beginUpdates() 
    tableView.endUpdates() 
} 

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    if indexPath.row == selectedRowIndex.row { 
     if cellTapped == false { 
      cellTapped = true 
      return 141 
     } else { 
      cellTapped = false 
      return 70 
     } 
    } 
    return 70 
} 

回答

2

您需要將電池的clipToBounds屬性設置爲YES(或選擇IB單元格的「剪輯子視圖」複選框),所以它的所有子視圖都不會顯示在單元格的邊界之外。文本視圖應該對contentView的邊以及高度約束有約束。它也應該對它上面的東西有一個約束,並且該視圖應該對contentView的頂部有一個約束。約束應該是這個樣子,

enter image description here

+0

設置「剪輯子視圖」對偉大的作品,用刷卡來刪除的例外。文本視圖重疊下面的單元格。 – user3746428 2014-10-12 13:23:39

+0

在哪裏設置剪輯子視圖@ user3746428? – 2017-04-10 14:14:48