标头中的“自定义视图”部分出现问题,无法在点击手势UITableView上呈现

我尝试了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()
        }
    }

请帮助我解决此问题。添加两个图像以说明单击前后的情况。

标头中的“自定义视图”部分出现问题,无法在点击手势UITableView上呈现

标头中的“自定义视图”部分出现问题,无法在点击手势UITableView上呈现

谢谢。

liyuan16888 回答:标头中的“自定义视图”部分出现问题,无法在点击手势UITableView上呈现

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2893435.html

大家都在问