How to make Xib footer items Clickable in tableView Swift

与世无争的帅哥 提交于 2021-01-29 16:42:11

问题


I am struggling to make my footer items clickable in tableView. In tableView I am using two different Xib's and I have used tableView - didSelect function as a expandable cell on click.

1) Main Xib

2) Child_View - Footer Xib

Now on footer items which is childView - I also want to make clickable action so on clicking it will navigate to viewController with their detail information.

  • How can I achieve this because didSelect is already in use for expandable cells?

Attaching three images

  • Main Xib
  • Expanded - Footer items (second Xib)
  • Highlighted one needs to be clickable

declare : var selectedIndex : Int! = -1

Code:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row == selectedIndex{
            selectedIndex = -1

        }else{
            selectedIndex = indexPath.row
        }
        tableView.reloadData()
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.row == selectedIndex
        {
            return UITableView.automaticDimension
        }else{
            return 71
        }
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return 1 
    }


    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "DownloadEntryViewCell", for: indexPath) as! DownloadEntryViewCell
        let dic = Appdata?[indexPath.row]
        var stackHeight:CGFloat = 0.0
        cell.fileNameLabel.text = dic?.date

        for i in Appdata ?? [] {
            let child_view = Bundle.main.loadNibNamed("FooterView", owner: self, options: nil)?.first as! FooterView
            child_view.projName.text = "\(i.projectName ?? "")" + "  " + "\(i.subTitle ?? "")"

            cell.stackViewFooter.addArrangedSubview(child_view)
            stackHeight = stackHeight + 60.0

        }
        cell.stackViewFooter.heightAnchor.constraint(equalToConstant: stackHeight).isActive = true
        return cell
    }

Images:

Main Expandable clickable

来源:https://stackoverflow.com/questions/61637065/how-to-make-xib-footer-items-clickable-in-tableview-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!