Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when opening cells in different sections #15

Closed
seanonthenet opened this issue Oct 28, 2017 · 14 comments
Closed

Crash when opening cells in different sections #15

seanonthenet opened this issue Oct 28, 2017 · 14 comments

Comments

@seanonthenet
Copy link

Hi. I get a crash when trying to open expandable cells in different sections. Index out of range. Works fine when opening multiple expandable cells in the same section just not in two (or more I'm assuming) different sections. I need this to work without closing the already opened cell. Not sure how to fix this.

Simplest ViewController code below:

import UIKit
import ExpandableCell



class MyTableViewController: UIViewController {

    
    @IBOutlet var tableView: ExpandableTableView!
    
    
    var cell: UITableViewCell {
        return tableView.dequeueReusableCell(withIdentifier: ExpandedButtonCell.ID)!
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        tableView.expandableDelegate = self
        //tableView.openAll()
        tableView.register(UINib(nibName: "NormalExpandableCell", bundle: nil), forCellReuseIdentifier: NormalExpandableCell.ID)
        tableView.register(UINib(nibName: "ExpandedButtonCell", bundle: nil), forCellReuseIdentifier: ExpandedButtonCell.ID)
    }
}


extension MyTableViewController: ExpandableDelegate {
    
    
    // Number of sections
    func numberOfSections(in expandableTableView: ExpandableTableView) -> Int {
        return 2
    }
    
    // Number of rows in section
    func expandableTableView(_ expandableTableView: ExpandableTableView, numberOfRowsInSection section: Int) -> Int {
        return 2
    }
    
    // Cells for row at (returns the main top level cells)
    func expandableTableView(_ expandableTableView: ExpandableTableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = expandableTableView.dequeueReusableCell(withIdentifier: NormalExpandableCell.ID) else { return UITableViewCell() }
        return cell
    }
    
    // Expanded Cells for row
    func expandableTableView(_ expandableTableView: ExpandableTableView, expandedCellsForRowAt indexPath: IndexPath) -> [UITableViewCell]? {
        return [cell, cell, cell]
    }
    
    // height for row
    func expandableTableView(_ expandableTableView: ExpandableTableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 100
    }
    
    
    // heights for expanded row at
    func expandableTableView(_ expandableTableView: ExpandableTableView, heightsForExpandedRowAt indexPath: IndexPath) -> [CGFloat]? {
        return [44, 44, 44]
    }

}


// EXPANDABLE CELLS HERE
class NormalExpandableCell: ExpandableCell {
    static let ID = "NormalExpandableCell"
}


class ExpandedButtonCell: UITableViewCell {
    static let ID = "ExpandedButtonCell"

}
@seanonthenet
Copy link
Author

Please could you let me know if it's a bug with ExpandableCell or with my implementation?

@younatics
Copy link
Owner

I will check it

@seanonthenet
Copy link
Author

Really appreciate it. Thank-you!

@nishaddangui
Copy link

same issue here,
tried closing all cells in didSelectRowAt , now error vanished but atleast one cell is left open since there is no deselect method.

@hadiidbouk
Copy link
Contributor

The problem is with the index of cells i guess, when you expand a cell the count of cells will changes.

@seanonthenet
Copy link
Author

@hadiidbouk Yes. Not sure how to fix that though.

@younatics
Copy link
Owner

Hello @nishaddangui , @hadiidbouk @Spark3000 ,
Could you show me your project file or other demo files so I can check error/bugs?
Thanks!

@hadiidbouk
Copy link
Contributor

The fact that i am working on a fork of this project to add the highlight methods, when i press on a cell the highlight will be on a wrong cell when there is a cell open, to fix the problem you can call a function after calling 'open' and 'close' in the ExpandableCell that can refresh the cells count.

@younatics
Copy link
Owner

@hadiidbouk Really appreciate if you send me PR :)

@hadiidbouk
Copy link
Contributor

Sure, when i finish from it 👍

@nishaddangui
Copy link

@younatics put closeAll() right before open(indexPath: indexPath, delegate: delegate) in didSelectRow
in your ExtendableTableView class
Kinda works for me

@ilyarmnzhdn
Copy link

can you solve this issue?

@pikaboo
Copy link
Collaborator

pikaboo commented Nov 26, 2018

I fixed this issue in one of the recent commits

@pikaboo pikaboo closed this as completed Nov 26, 2018
@tadeha
Copy link

tadeha commented Apr 6, 2020

@pikaboo How did you fix this?
Because I have the same problem in didSelectRow function. It's returning a wrong indexPath.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants