2016-07-26 52 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来解决此问题。但我不喜欢硬编码的价值。如何停止向表格单元格渗透标题视图? –

相关问题