ExpandingStackCells icon indicating copy to clipboard operation
ExpandingStackCells copied to clipboard

Expansion doesn't work with many cells.

Open jozsef-vesza opened this issue 9 years ago • 6 comments

  • Initialize with multiple elements: 8 works for me on an iPhone 6 simulator. The point is that you have to scroll down to see the last element.
  • Tap on the last element.
  • It won't expand.

jozsef-vesza avatar Nov 02 '15 14:11 jozsef-vesza

Expansion still works for me if I make each different cell it's own custom cell 915d231aee40cac80933446c4fcca934

By the way, thank you so much for this, I couldn't find anything that worked for me!

michael-mckenna avatar Jan 11 '16 18:01 michael-mckenna

I have a similar issue having more cells then can be displayed. I found that if a cell becomes visible and then gets removed from the visible cells, it can no longer expand. Occasionally when i was testing this i would get a broken constraint; however i as not able to replicated it consistently.

uistackissue1080

Please note here that item 9 was pushed offscreen when expanding item 1.

jrail49 avatar Jan 28 '16 06:01 jrail49

I have fixed the bug, the original problem is caused by setSelect method in cell, every time you move the sell to let new cell show, this method will be called.

The solution is create a new func, and move the mode in setSelect into your new func, and call this func in didselect

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    let cell = tableView.cellForRowAtIndexPath(indexPath) as! TweetsCell
    cell.changeCellStatus(true)
    tableView.beginUpdates()
    tableView.endUpdates()
}

func changeCellStatus(selected: Bool){
    UIView.animateWithDuration(0.5,
        delay: 0,
        usingSpringWithDamping: 1,
        initialSpringVelocity: 1,
        options: UIViewAnimationOptions.CurveEaseIn,
        animations: { () -> Void in
            self.stackView.arrangedSubviews.last?.hidden = !selected
        },
        completion: nil)
}

Be care about current status.

lvlingsheng avatar Feb 21 '16 23:02 lvlingsheng

@lvlingsheng thanks for digging this one up! Do you mind opening a PR? :)

jozsef-vesza avatar Feb 22 '16 10:02 jozsef-vesza

@jozsef-vesza That last element issue is because of your willSelectRowAtIndexPath

Also the above solution regarding the issue by @jrail49 didn't work so I implemented a variant of it. So as above

  • Removed the setSelected method from the cell
  • Moved the animation into changeCellStatus()
  • Implemented code below

Now the only thing missing is deselecting an already selected

       override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {

        if let selectedIndex = tableView.indexPathForSelectedRow where selectedIndex == indexPath {

            if let cell = tableView.cellForRowAtIndexPath(indexPath) as? ExpandingCell {
                tableView.beginUpdates()
                tableView.deselectRowAtIndexPath(indexPath, animated: true)
                cell.changeCellStatus(false)
                tableView.endUpdates()
            }

            return nil
        }

        return indexPath
    }

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        let cell = tableView.cellForRowAtIndexPath(indexPath) as! ExpandingCell
        cell.changeCellStatus(true)
        self.tableView.beginUpdates()
        self.tableView.endUpdates()
    }

    override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {

        if let cell = tableView.cellForRowAtIndexPath(indexPath) as? ExpandingCell {
            cell.changeCellStatus(false)
            self.tableView.beginUpdates()
            self.tableView.endUpdates()
        }
    }

acegreen avatar Mar 05 '16 22:03 acegreen

@acegreen have you fixed this issue? I'm using this framework right now and have the same problem.

tangert avatar Aug 06 '16 05:08 tangert