I have an issue with expanding and collapsing UiTableView rows and not sure how to troubleshoot or what may be the cause. When the section expands it causes a jerking motion and other rows seem to move up and down.
Here is the issue:
https://www.useloom.com/share/14c1cdd27e7844dcad31dad30d4aa1ce
When the row is toggled the following code is executed:
section.showPrompts = !section.showPrompts;
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
You could try batching the updates within
[self.tableview beginUpdates];
... your code ...
[self.tableview endUpdates];
so that all of the animations are synchronized.
Related
When I'm trying to insert section 0 using -insertSections:withRowAnimation: with UITableViewRowAnimationTop tableHeaderView affected by animation(It collapses and expanded to original size again). Other animation types work as expected.
[self.tableView beginUpdates];
if (changes.insertedSectionsIndexes.count > 0) {
[self.tableView insertSections:changes.insertedSectionsIndexes withRowAnimation:UITableViewRowAnimationTop];
}
[self.tableView endUpdates];
I have UITableView with variable height custom cells and multiple sections which are not fixed, i am trying to implement load more functionality while user reach at first cell.
After fetching data i am arranging records into NSMutableArray which contains multi-dimensional array to store data section vice.
My problem is when i load more data i don't have idea about how many sections and how many rows in each section comes. So i can not add fix values to move my UITableView at particular position using methods like scrollToRowAtIndexPath or scrollRectToVisible
So every time after getting new record i called reloadData to update my number Of Sections and number Of Rows In Each Section, which also move control to first row of UITableView. I want to be present at current viewing cell not at first cell.
I have also tried answers at reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling this question but that are not helping me.
Don't use reloadData if you want to stay at the same position. Use reloadRowsAtIndexPaths or insertRowsAtIndexPaths or reloadSections instead.
To refresh modified rows with animation:
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:#[indexPathOfYourModifiedCell] withRowAnimation: UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
To add rows with animation (number of rows is automatically increased):
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:#[indexPathOfYourNewCell] withRowAnimation: UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
Without animation (untested):
[UIView performWithoutAnimation:^{
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:#[indexPathOfYourNewCell] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
}];
Apple documentation: description here
I have a UITableView where I move a row from outside the visible scroll area to the top of the UITableView. The animation works as intended but it ends up showing a duplicate cell of what was previously at index 0.
Code looks something like this except for the hardcoded index:
[self.tableView beginUpdates];
[self.tableView moveRowAtIndexPath:[NSIndexPath indexPathForItem:16 inSection:0] toIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
[self.tableView endUpdates];
I have this problem on both iOS 8 & iOS 7. Anyone have an idea how to solve this?
The cause of the problem was a bug in the re-ordering of my data provider. I moved a cell in the tableview but the data array did not reflect that change.
I have a UITableView that is made up of sections with 1 row in each section. This is done so that I can get buffer space between each row. When the user deletes a row, they are de facto deleting the whole section.
My row deletion code in commitEditingStyle is:
[self.habitsToView removeObjectAtIndex:[indexPath section]];
[tableView beginUpdates];
[tableView deleteSections:[NSIndexSet indexSetWithIndex:[indexPath section]] withRowAnimation:UITableViewRowAnimationTop];
[tableView endUpdates];
But when a row is deleted, the animation is wrong. The row itself slides off to the left, and the delete button slides upwards. This happens no matter what value I use for withRowAnimation
Anyone know what could be causing the strange animation?
I have an array of HTML strings, some of them are with photos, some of them long, some short, some with links - they are all different.
Now I have a UITableView and I want to display those HTML strings on the table, each string in each cell by it's index. My problem is that I don't know the height of each cell, I need to calculate the height by the height of each HTML string, but I can only know it after the UIWebView is loaded.
I need a suggestion for a good solution to this issue, something that will looks good. I've already tried to use UIWebViewDelegate to change the cell frame after loading the HTML string into the WebView but it looks bad.. and messes the table view completely.
Thanks in advance.
Resort to animation when adding the cells.
Add the cells one by one (1 indexPath at a time) in your UITableView (and datasource), by doing this:
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:#[indexPath]
withRowAnimation:UITableViewRowAnimationFade];
// or UITableViewRowAnimationNone
[self.tableView endUpdates];
Your UITableView will slowly grow with an animation as the data becomes available.
If you need to resize an existing cell, delete it and immediately re-insert it, all within a single beginUpdates/endUpdates sequence:
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:#[indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths:#[indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];