Ios 节中标题的自定义视图有问题,点击时未呈现手势UITableView

Ios 节中标题的自定义视图有问题,点击时未呈现手势UITableView,ios,uitableview,swift5,uitableviewsectionheader,Ios,Uitableview,Swift5,Uitableviewsectionheader,我尝试了n个解决方案,但仍然没有成功。我为节的标题设计了自己的自定义单元格。因此,我的表呈现正确。 然后,对于funcviewForHeaderInSection()中的每个标题单元格,我添加了点击手势来处理点击标题。但每次我点击任何标题,它就会从表中消失。我还没有写任何删除节的代码 func numberOfSections(in tableView: UITableView) -> Int { return ModelFacade.sharedInstanceModel

我尝试了n个解决方案,但仍然没有成功。我为节的标题设计了自己的自定义单元格。因此,我的表呈现正确。 然后,对于func
viewForHeaderInSection()
中的每个标题单元格,我添加了点击手势来处理点击标题。但每次我点击任何标题,它就会从表中消失。我还没有写任何删除节的代码

func numberOfSections(in tableView: UITableView) -> Int {
        return ModelFacade.sharedInstanceModelFacade.getGenericModel().faqsArray.count
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let cell = tableView.dequeueReusableCell(withIdentifier: "AccordianHeaderPrototypeCell") as! AccordianHeaderPrototypeCell
        let cellinfo = ModelFacade.sharedInstanceModelFacade.getGenericModel().faqsArray[section]
        cell.headingLabel.text = cellinfo.title
        
        cell.arrowImage.tag = kHeaderSectionTag + section
        cell.arrowImage.image = Constants.DOWNARROW_IMAGE
        
        cell.tag = section
        let headerTapGesture = UITapGestureRecognizer()
        headerTapGesture.addTarget(self, action: #selector(self.sectionHeaderWasTouched(_:)))
        cell.addGestureRecognizer(headerTapGesture)
        return cell
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if (self.expandedSectionHeaderNumber == section) {
            return ModelFacade.sharedInstanceModelFacade.getGenericModel().faqsArray[section].contentArray.count
        } else {
            return 0;
        }
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ProductDetailingsPrototypeCell", for: indexPath) as! ProductDetailingsPrototypeCell
        cell.separatorInset = .zero
        let cellinfo = ModelFacade.sharedInstanceModelFacade.getGenericModel().faqsArray[indexPath.section].contentArray[indexPath.row]
        cell.descriptionLabel.attributedText = cellinfo.html2Attributed
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }
    
    @objc func sectionHeaderWasTouched(_ sender: UITapGestureRecognizer) {
        let headerView = sender.view as! AccordianHeaderPrototypeCell
        let section = headerView.tag
        let eImageView = headerView.viewWithTag(kHeaderSectionTag + section) as? UIImageView
        if (self.expandedSectionHeaderNumber == -1) {
            self.expandedSectionHeaderNumber = section
            tableViewExpandSection(section, imageView: eImageView!)
        } else {
            if (self.expandedSectionHeaderNumber == section) {
                tableViewCollapeSection(section, imageView: eImageView!)
            } else {
                let cImageView = self.view.viewWithTag(kHeaderSectionTag + self.expandedSectionHeaderNumber) as? UIImageView
                tableViewCollapeSection(self.expandedSectionHeaderNumber, imageView: cImageView!)
                tableViewExpandSection(section, imageView: eImageView!)
            }
        }
    }
    
    func tableViewCollapeSection(_ section: Int, imageView: UIImageView) {
        let sectionData = ModelFacade.sharedInstanceModelFacade.getGenericModel().faqsArray[section].contentArray
        self.expandedSectionHeaderNumber = -1
        if (sectionData.count == 0) {
            return
        } else {
            UIView.animate(withDuration: 0.4, animations: {
                imageView.transform = CGAffineTransform(rotationAngle: (0.0 * CGFloat(Double.pi)) / 180.0)
            })
            var indexesPath = [IndexPath]()
            for i in 0 ..< sectionData.count {
                let index = IndexPath(row: i, section: section)
                indexesPath.append(index)
            }
            self.itemsTableView!.beginUpdates()
            self.itemsTableView!.deleteRows(at: indexesPath, with: UITableView.RowAnimation.fade)
            self.itemsTableView!.endUpdates()
        }
    }
    
    func tableViewExpandSection(_ section: Int, imageView: UIImageView) {
        let sectionData = ModelFacade.sharedInstanceModelFacade.getGenericModel().faqsArray[section].contentArray
        if (sectionData.count == 0) {
            self.expandedSectionHeaderNumber = -1
            return
        } else {
            UIView.animate(withDuration: 0.4, animations: {
                imageView.transform = CGAffineTransform(rotationAngle: (180.0 * CGFloat(Double.pi)) / 180.0)
            })
            var indexesPath = [IndexPath]()
            for i in 0 ..< sectionData.count {
                let index = IndexPath(row: i, section: section)
                indexesPath.append(index)
            }
            self.expandedSectionHeaderNumber = section
            self.itemsTableView.beginUpdates()
            self.itemsTableView.insertRows(at: indexesPath, with: UITableView.RowAnimation.fade)
            self.itemsTableView.endUpdates()
        }
    }
func numberOfSections(在tableView:UITableView中)->Int{
返回ModelFacade.sharedInstanceModelFacade.getGenericModel().faqsArray.count
}
func tableView(tableView:UITableView,viewForHeaderInSection:Int)->UIView?{
让cell=tableView.dequeueReusableCell(标识符为:“AccordianHeaderPrototypeCell”)作为!AccordianHeaderPrototypeCell
让cellinfo=ModelFacade.sharedInstanceModelFacade.getGenericModel().faqsArray[部分]
cell.headingLabel.text=cellinfo.title
cell.arrowImage.tag=kHeaderSectionTag+节
cell.arrowImage.image=Constants.DOWNARROW\u image
cell.tag=节
让HeaderTapSignature=UITapSignature识别器()
HeaderTapSirture.addTarget(self,action:#选择器(self.sectionHeaderWastuched(:))
cell.AddGestureRecognitor(HeaderTap手势)
返回单元
}
func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
if(self.expandedSectionHeaderNumber==节){
返回ModelFacade.sharedInstanceModelFacade.getGenericModel().faqsArray[section].contentArray.count
}否则{
返回0;
}
}
func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
让cell=tableView.dequeueReusableCell(标识符为:“ProductDetailingsPrototypeCell”,for:indexPath)作为!ProductDetailingsPrototypeCell
cell.separatorInset=.0
让cellinfo=ModelFacade.sharedInstanceModelFacade.getGenericModel().faqsArray[indexPath.section].contentArray[indexPath.row]
cell.descriptionLabel.AttributeText=cellinfo.html2Attributed
返回单元
}
func tableView(tableView:UITableView,heightForRowAt indexath:indexPath)->CGFloat{
返回UITableView.automaticDimension
}
@objc func SECTIONHEADERWASHOTED(uu发送方:UITAPGESTURE识别器){
让headerView=sender.view为!AccordianHeaderPrototypeCell
let section=headerView.tag
将eImageView=headerView.viewWithTag(kHeaderSectionTag+section)设为UIImageView
if(自展开节标题编号==-1){
self.expandedSectionHeaderNumber=节
tableViewExpandSection(section,imageView:eImageView!)
}否则{
if(self.expandedSectionHeaderNumber==节){
tableViewCollapeSection(部分,图像视图:eImageView!)
}否则{
将cImageView=self.view.viewWithTag(kHeaderSectionTag+self.expandedSectionHeaderNumber)设为UIImageView
tableViewCollapeSection(self.expandedSectionHeaderNumber,imageView:cImageView!)
tableViewExpandSection(section,imageView:eImageView!)
}
}
}
func tableViewCollapeSection(uSection:Int,imageView:UIImageView){
让sectionData=ModelFacade.sharedInstanceModelFacade.getGenericModel().faqsArray[section].contentArray
self.expandedSectionHeaderNumber=-1
如果(sectionData.count==0){
返回
}否则{
UIView.animate(持续时间:0.4,动画:{
imageView.transform=CGAffineTransform(旋转角度:(0.0*CGFloat(Double.pi))/180.0)
})
var indexesPath=[IndexPath]()
对于0中的i..
添加两个图像以解释单击前后发生的情况


嘿,你能检查下一行中
indexesPath
的值吗:
self.itemsTableView!。deleteRows(在:indexesPath处,使用:UITableView.RowAnimation.fade)
而不是删除和插入,您可以选择仅在
numberOfRowsInSection中切换行数