1

I am working on a UITableView with a custom row (single row), that I load from a separate xib file. UITableView also has a sticky footer view.

Everything is working fine except that when I tap on the footer view, the UITableView's delegate method tableView(_:didSelectRowAt:) is being called, and that's weird.

The IndexPath that I received inside that method is [0,0]. Now how that is problematic for me? Well I am doing a certain thing when the cell of that tableview is pressed. But under the current scenario, that certain thing is also being done when I press footer view instead of the cell.

The code for UITableView is:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    guard let cell = tableView.dequeueReusableCell(
        withIdentifier: CellIdentifiers.INVITE_CELL_ID,
        for: indexPath) as? InviteCell else {

        return UITableViewCell()
    }

    // cell configuration

    return cell
}

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {

    if (contacts.count > 0) {

        guard let footer = tableView.dequeueReusableCell(
            withIdentifier: CellIdentifiers.INVITE_FOOTER_CELL_ID)
            as? InviteFooter else {

                return nil
        }

        footer.delegate = self

        return footer
    }
    return nil
}

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

    if (contacts.count > 0) {
        return 90
    }
    return 0
}
Meeran Tariq
  • 1,366
  • 11
  • 23
  • Can you post the footer implementation code? – Shreeram Bhat Sep 18 '19 at 15:29
  • Could you update the question with some code? how do you load the cell? how do you set the tableFooterView? You could use a section footer instead? – Lucho Sep 18 '19 at 15:29
  • Updated my question – Meeran Tariq Sep 18 '19 at 15:41
  • There are other delegate and datasource methods there too, like didSelectRowAt and numberOfSections – Meeran Tariq Sep 18 '19 at 15:42
  • 1
    Why are you using a cell as footerView? that is strange. Also, what does the `footer.delegate`? does it handle selection? – Lucho Sep 18 '19 at 15:43
  • Maybe there is a cell hidden under your footer, triggering the selectRow method? – koen Sep 18 '19 at 15:43
  • There's only one cell inside the tableview , and that is appearing above the footer view. So i don't think there's any cell hidden under it. And i was using two sections at first, and then i decided to use one section only and use footer view instead of second section. That's why i have a cell for footer view. Do you think this maybe a problem? and is should use view instead of cell? – Meeran Tariq Sep 18 '19 at 15:48
  • 1
    @MeeranTariq - it does seem a bit odd to use a `UITableViewCell` for a section footer view, particularly if you only have one section. Tough to say what might be going on though, without more code (like, what's going on in that "footer cell"?). If you replace the section footer view with a regular view and the problem persists, review [mcve] to get more help here. – DonMag Sep 18 '19 at 16:01
  • 1
    I agree with @DonMag, try returning a UIView(with nothing more) instead of a cell and see if the problem persists. – Lucho Sep 18 '19 at 16:10
  • @DonMag thanks man, that actually was the issue. Using UIView solved the problem. – Meeran Tariq Sep 18 '19 at 16:24
  • @Lucho thanks to you too man – Meeran Tariq Sep 18 '19 at 16:24
  • @MeeranTariq Glad it helped! – Lucho Sep 18 '19 at 18:02

0 Answers0