简体   繁体   English

如何在展开和折叠的表视图中设置节边框?

[英]How to set Section Border In tableview With Expanding and Collapsing?

I'm Creating an design.我正在创建一个设计。 In this Design I have to set Border colour for Section with collapsing and Expanding.在此设计中,我必须为具有折叠和展开功能的部分设置边框颜色。 I created a Xib file for Custom section but it's only show border colour in section.我为自定义部分创建了一个 Xib 文件,但它只在部分中显示边框颜色。 I want the Colour for whole section.我想要整个部分的颜色。 No matter how many rows are inside.不管里面有多少行。 and My first section Only expanding... If click on other it is not exapnding.和我的第一部分仅扩展...如果单击其他部分则不会扩展。 Section o is expand. o 部分是展开的。

struct Section {
var name: String!
var items: [String]!
var collapsed: Bool!

init(name: String, items: [String]) {
self.name = name
self.items = items
self.collapsed = true
}
}

  func tableView(_ tableView: UITableView, numberOfRowsInSection 
   section: Int) -> Int {
    if tableView == self.preparingTableView {
        return 2
    } else {
        return (sections[section].collapsed!) ? 0 : 4
    }

}

This is the function for checking toggle button这是用于检查切换按钮的 function

@objc func toggleCollapse(sender: UIButton) {
  let section = sender.tag
  let collapsed = sections[section].collapsed
   
    sections[section].collapsed = !collapsed!

  // Reload section
    self.wareHouseTable.reloadSections(NSIndexSet(index: section) 
    as IndexSet, with: .automatic)
   }

this is what i want.这就是我要的。 在此处输入图像描述

This is My xib File这是我的 xib 文件在此处输入图像描述

you can use section and cell such as bellow pic:您可以使用部分和单元格,例如下面的图片:

in header section there are 3 line(or view with gray color) or a view with border(right,left,top) and cell there are 2 view in right,left equal constraint with section在 header 部分有 3 条线(或灰色视图)或带边框的视图(右、左、上)和单元格在右、左等约束条件下有 2 个视图

you must remove separator and add a line above cell such as pic:您必须删除分隔符并在单元格上方添加一行,例如 pic:

finally also you must check the last cell, and show bottom cell最后你还必须检查最后一个单元格,并显示底部单元格

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM