2016-07-26 42 views
0

我有兩個原型單元格。其中一個用於顯示數據&其他我用於標題視圖。多個原型單元格標題在刪除時移動

當我嘗試刪除我的常規細胞。標題單元隨它一起移動。

enter image description here

我不想頭,當我試圖刪除定期細胞移動。

我已禁用標題原型單元格上的用戶交互。它仍然在繼續前進。在提交編輯樣式中,我立即返回標題原型單元格。它仍然在繼續前進。我不知道還有什麼要做。請幫忙。

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 

    if tableView == upcomingTableView { 

     if let headerCell = tableView.dequeueReusableCellWithIdentifier("headerCell") { 

      headerCell.textLabel?.text = sectionNames[section] 

      headerCell.detailTextLabel?.text = "Rs\(sum[section])" 

      headerCell.detailTextLabel?.textColor = UIColor.blackColor() 

      headerCell.backgroundColor = UIColor.lightGrayColor() 

      return headerCell 
     } 
    } 

    return nil 
} 

cell for row at index path is also regular code。

+0

從表視圖委託方法添加一些代碼。 –

回答

1

更新答:

創建的UIView並添加tableViewCell爲子視圖並返回的UIView。

解決方案在斯威夫特:

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 

    if let headerCell = tableView.dequeueReusableCellWithIdentifier("headerCell") { 

     //Create an UIView programmatically 
     let headerView = UIView() 

     headerCell.textLabel?.text = (section == 0) ? "Apple" : "Microsoft" 
     headerCell.backgroundColor = UIColor.lightGrayColor() 

     //Add cell as subview to UIView 
     headerView.addSubview(headerCell) 

     //Return the header view 
     return headerView 
    } 

    return nil 

} 

輸出:

enter image description here

+0

感謝您嘗試使內容查看空白單元格。我還創建了新的新項目並嘗試使用假數據。內容視圖呈現空白空白。 –

+0

@ApoorvMote:標題View與其他單元格一起移動的原因是因爲它繼承了UITableViewCell的特性,即在編輯時向左滑動。是的,返回cell.contentView不工作是因爲這個我猜。我將使用Sample Swift Code更新我的答案。 – Tesan3089

+0

它修復了刪除問題,但它爲我創建了另一個問題。標題視圖滲入表格單元格。我可以通過將頭部視圖高度硬編碼到44.0 CGFloat來解決此問題。但我不喜歡硬編碼的價值。如何停止向表格單元格滲透標題視圖? –

相關問題