ExpandingStackCells
ExpandingStackCells copied to clipboard
Expansion doesn't work with many cells.
- 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.
Expansion still works for me if I make each different cell it's own custom cell
By the way, thank you so much for this, I couldn't find anything that worked for me!
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.
Please note here that item 9 was pushed offscreen when expanding item 1.
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 thanks for digging this one up! Do you mind opening a PR? :)
@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 have you fixed this issue? I'm using this framework right now and have the same problem.