I have a UITableView, in which each cell has a button.
When the button is clicked, the cell's height will be changed.
Of course, the whole tableview height will be changed according to it.
I cannot find a way during long surfing.
What is an elegant solution to achieve this?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- Popover segue to static cell UITableView causes co
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
(See this answer. Kudos to Tapas Pal for writing the original answer. I just changed it to better fit your question.)
You will need a
BOOL
variable to tell the cell that its height should be different from the others. You will also need a number (here, I will useNSInteger
) variable so that you can increase the height for the right cell.Then, in your
-tableView:cellForRowAtIndexPath:
method, add the following to where you design your cell. You will set the button tag to be the same as its cell's row so that you know what cell to expand. Moreover, if you need to add any elements to the cell, you can do it inside theif
statement.Moving to the button's
IBAction
. When the button is tapped, theUITableView
will reload the cell that button is on. Note: if you use multiple sections in yourUITableView
, you will need to add another number variable to account for that. Comment if you need help.Finally, in the
-tableView:heightForRowAtIndexPath:
method:What this does is check if a cell is expected to be expanded and, if so, whether that cell is the one currently being asked for a height value. If it is, then the returned value is the expanded height. If not, the original one.
Call the function
- reloadRowsAtIndexPaths:withRowAnimation:
. Implement functionUITableViewDelegate
function- tableView:heightForRowAtIndexPath:
and return the new height.