Ios Tableview标题单元格是否在swift中使用相同的cardView展开?
我已附加图像单击卡片视图在表格单元格内动态扩展同一张卡片其可通过性以实现此目的 我找了很多,但没有工作 使用CardView收听我的代码添加的标题单元格 添加箭头按钮以单击按钮展开单元格 它可以扩展,但不能在父卡中显示差异卡 我已经添加了我的源代码Ios Tableview标题单元格是否在swift中使用相同的cardView展开?,ios,objective-c,swift,uitableview,Ios,Objective C,Swift,Uitableview,我已附加图像单击卡片视图在表格单元格内动态扩展同一张卡片其可通过性以实现此目的 我找了很多,但没有工作 使用CardView收听我的代码添加的标题单元格 添加箭头按钮以单击按钮展开单元格 它可以扩展,但不能在父卡中显示差异卡 我已经添加了我的源代码 var hiddenSections = Set<Int>() let tableViewData = [ ["1","2","3","4","5"], ["1","2","3
var hiddenSections = Set<Int>()
let tableViewData = [
["1","2","3","4","5"],
["1","2","3","4","5"],
["1","2","3","4","5"],
]
override func viewDidLoad() {
super.viewDidLoad()
let CustomeHeaderNib = UINib(nibName: "CustomSectionHeader", bundle: Bundle.main)
historyTableView.register(CustomeHeaderNib, forHeaderFooterViewReuseIdentifier: "customSectionHeader")
}
func numberOfSections(in tableView: UITableView) -> Int {
return self.tableViewData.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if self.hiddenSections.contains(section) {
return 0
}
return self.tableViewData[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = self.tableViewData[indexPath.section][indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return view.frame.width/4
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = self.historyTableView.dequeueReusableHeaderFooterView(withIdentifier: "customSectionHeader") as! CustomSectionHeader
header.setupCornerRadious()
let sectionButton = header.expandBtn
sectionButton?.setTitle(String(section),
for: .normal)
sectionButton?.tag = section
sectionButton?.addTarget(self,action: #selector(self.hideSection(sender:)), for: .touchUpInside)
return header
}
@objc
private func hideSection(sender: UIButton) {
let section = sender.tag
func indexPathsForSection() -> [IndexPath] {
var indexPaths = [IndexPath]()
for row in 0..<self.tableViewData[section].count {
indexPaths.append(IndexPath(row: row,
section: section))
}
return indexPaths
}
if self.hiddenSections.contains(section) {
self.hiddenSections.remove(section)
self.historyTableView.insertRows(at: indexPathsForSection(),
with: .fade)
} else {
self.hiddenSections.insert(section)
self.historyTableView.deleteRows(at: indexPathsForSection(),
with: .fade)
}
}
var hiddenSections=Set()
让tableViewData=[
["1","2","3","4","5"],
["1","2","3","4","5"],
["1","2","3","4","5"],
]
重写func viewDidLoad(){
super.viewDidLoad()
让CustomeHeaderNib=UINib(nibName:“CustomSectionHeader”,bundle:bundle.main)
historyTableView.register(CustomeHeaderNib,forHeaderFooterViewReuseIdentifier:“customSectionHeader”)
}
func numberOfSections(在tableView:UITableView中)->Int{
返回self.tableViewData.count
}
func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
如果self.hiddenSections.contains(节){
返回0
}
返回self.tableViewData[节].count
}
func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
let cell=UITableViewCell()
cell.textLabel?.text=self.tableViewData[indexPath.section][indexPath.row]
返回单元
}
func tableView(u tableView:UITableView,heightForHeaderInSection:Int)->CGFloat{
返回视图.frame.width/4
}
func tableView(tableView:UITableView,viewForHeaderInSection:Int)->UIView?{
让header=self.historyTableView.dequeueReusableHeaderFooterView(带有标识符:“customSectionHeader”)作为!customSectionHeader
header.setupCornerRadious()
让sectionButton=header.expandBtn
sectionButton?设置标题(字符串(节),
适用于:。正常)
sectionButton?.tag=节
sectionButton?.addTarget(self,action:#选择器(self.hideSection(sender:)),for:.touchUpInside)
回流集管
}
@objc
私有函数隐藏区(发送方:UIButton){
让section=sender.tag
func IndexPath函数()->[IndexPath]{
var IndexPath=[IndexPath]()
对于0..中的行,也可以实现这一点。要做到这一点
1.返回单元格高度作为节高度。如果用户单击单元格,则返回特定单元格的总内容高度
2.您需要获取一个数组,如果用户选择了单元格,则将indexPath编号添加到数组中。如果选择已展开单元格,则将其从数组中移除。在索引处的行高度中检查indexPath是否在数组中
这是一种方法。使用节也可以做到这一点。//MARK:-UITableView相关方法
//MARK:- UITableView Related Methods
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrDict.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
// var cel = tblExpandedTest.dequeueReusableCellWithIdentifier("expCell", forIndexPath: indexPath) as! CDTableViewCell
var cel : CaseHearingTabTVC! = tableView.dequeueReusableCell(withIdentifier: "caseHearingTabCell") as! CaseHearingTabTVC
if(cel == nil)
{
cel = Bundle.main.loadNibNamed("caseHearingTabCell", owner: self, options: nil)?[0] as! CaseHearingTabTVC;
}
//cell?.backgroundColor = UIColor.white
cel.delegate = self
if indexPath != selctedIndexPath{
cel.subview_desc.isHidden = true
cel.subview_remarks.isHidden = true
cel.lblHearingTime.isHidden = true
}
else {
cel.subview_desc.isHidden = false
cel.subview_remarks.isHidden = false
cel.lblHearingTime.isHidden = false
}
return cel
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
selectIndex = true;
if(selectedInd == indexPath.row) {
selectedInd = -1
}
else{
let currentCell = tableView.cellForRow(at: indexPath)! as! CaseHearingTabTVC
cellUpdatedHeight = Float(currentCell.lblHearingTime.frame.origin.y + currentCell.lblHearingTime.frame.size.height) + 2;
selectedInd = -1
tblCaseHearing.reloadData()
selectedInd = indexPath.row
}
let previousPth = selctedIndexPath
if indexPath == selctedIndexPath{
selctedIndexPath = nil
}else{
selctedIndexPath = indexPath
}
var indexPaths : Array<IndexPath> = []
if let previous = previousPth{
indexPaths = [previous]
}
if let current = selctedIndexPath{
indexPaths = [current]
}
if indexPaths.count>0{
tblCaseHearing.reloadRows(at: indexPaths, with: UITableView.RowAnimation.automatic)
}
}
func tableView(_ tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowIndexPath indexPath:IndexPath) {
(cell as! CaseHearingTabTVC).watchFrameChanges()
}
func tableView(_ tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowIndexPath indexPath:IndexPath) {
(cell as! CaseHearingTabTVC).ignoreFrameChanges()
}
func tableView(_ TableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{
if indexPath == selctedIndexPath{
return CGFloat(cellUpdatedHeight)
}else{
return CaseHearingTabTVC.defaultHeight
}
}
func numberOfSections(在tableView:UITableView中)->Int{
返回1
}
func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
返回arrDict.count
}
func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell
{
//var cel=tblExpandedTest.dequeueReusableCellWithIdentifier(“expCell”,forindexath:indexPath)as!CDTableViewCell
var cel:CaseHearingTabTVC!=tableView.dequeueReusableCell(标识符为:“caseHearingTabCell”)作为!CaseHearingTabTVC
如果(cel==nil)
{
cel=Bundle.main.loadNibNamed(“caseHearingTabCell”,所有者:self,选项:nil)?[0]作为!CaseHearingTabTVC;
}
//单元格?.backgroundColor=UIColor.white
cel.delegate=self
如果indexPath!=selctedIndexPath{
cel.subview_desc.ishiden=true
cel.subview_comments.ishiden=true
cel.lblHearingTime.ishiden=true
}
否则{
cel.subview_desc.ishiden=false
cel.subview_comments.ishiden=false
cel.lblHearingTime.ishiden=false
}
返回cel
}
func tableView(tableView:UITableView,didSelectRowAt indexPath:indexPath){
selectIndex=true;
if(selectedId==indexPath.row){
selectedId=-1
}
否则{
让currentCell=tableView.cellForRow(at:indexPath)!as!CaseHearingTabTVC
cellUpdatedHeight=Float(currentCell.lblHearingTime.frame.origin.y+currentCell.lblHearingTime.frame.size.height)+2;
selectedId=-1
tblcasehearning.reloadData()
selectedInd=indexPath.row
}
设previousPth=selctedIndexPath
如果indexPath==selctedIndexPath{
selctedIndexPath=nil
}否则{
selctedIndexPath=indexPath
}
变量索引路径:数组=[]
如果let previous=previousPth{
indexPaths=[上一个]
}
如果let current=selctedIndexPath{
indexPaths=[当前]
}
如果indexPaths.count>0{
tblcasehearning.reloadRows(at:indexPaths,with:UITableView.rownanimation.automatic)
}
}
func tableView(tableView:UITableView,willDisplayCell:UITableViewCell,forRowIndexPath-indexPath:indexPath){
(单元格为!CaseHearingTabTVC).watchFrameChanges()
}
func tableView(tableView:UITableView,DiEndDisplayingCell:UITableViewCell,forRowIndexPath indexPath:indexPath){
(单元格为!CaseHearingTabTVC).ignoreFrameChanges()
}
func tableView(tableView:UITableView,heightForRowAt indexath:indexPath)->CGFloat{
如果indexPath==selctedIndexPath{
返回CGFloat(cellUpdatedHeight)
}否则{
返回箱听力默认高度
}
}
func tableView(tableView:UITableView,heightForRowAt indexath:indexPath)->CGFloat{
guard let index = selectedIndex else {
return 115
}
if index == indexPath.row{
return 200
}
return 115
}
func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
if let selected = selectedIndex, selected == indexPath.row{
let cell = tableView.dequeueReusableCell(withIdentifier: "ExpandedCardCell", for: indexPath) as! ExpandedCardCell
return cell
}
let cell = tableView.dequeueReusableCell(withIdentifier: "CardCell", for: indexPath) as! CardCell
return cell
}
func tableView(tableView:UITableView,didSelectRowAt indexPath:indexPath){
如何做到这一点,如果你有任何样本,请分享?我已经这样做了。我无法分享该代码。但我会给你发送样本代码。给我一些时间,我会发送它。你找到解决方案了吗?我正在寻找
if let selected = selectedIndex, selected == indexPath.row{
let cell = tableView.dequeueReusableCell(withIdentifier: "ExpandedCardCell", for: indexPath) as! ExpandedCardCell
return cell
}
let cell = tableView.dequeueReusableCell(withIdentifier: "CardCell", for: indexPath) as! CardCell
return cell
}
if selectedIndex == indexPath.row{
selectedIndex = nil
}
else{
selectedIndex = indexPath.row
}
UIView.performWithoutAnimation {
tableView.reloadData()
}
}