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?
Related
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.
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
While writing a UITableView in iOS8 I've implemented swipe left/right gestures similar to that in Mail. I would now like to implement a cell that slides down below the cell which the user has just swiped left and tapped a button on. Can anyone point me in the right direction?
You need to add the row that should slide out to the data model (UITableViewDataSource) of your UITableView, then tell the tableview section to update with an animation:
[self.tableView beginUpdates];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];
I have a Table view. When the user swipes to the left the delete button appears and he is able to remove this entry. But now I've made some strange experiences with the row animation. When the user then clicks on the delete button it stays there but the normal cell is moved. After the cell content view has disappeard the delete button exits also.
What's the problem here?
[[eventDataDictionary objectForKey:key] removeObject:[sortedArray objectAtIndex:indexPath.row]];
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationMiddle];
[tableView endUpdates];
Thanks and best regards from Germany,
Chris
I don't think you need beginUpdates, endUpdates. deleteRowsAtIndexPaths: has its own animation parameter. Just remove the begin~end end try again.
Here is my program. I want to create a simple list of items that display a number. When the rows are tapped the number will increment by one.
EDIT: Is it proper to change the UI of a row in the didSelectRowAtIndexPath function?
I created a UIViewController in Xcode 5 through a storyboard and it does everything right except I can't seem to stop the [tableView reloadData] from deselecting my row after being tapped. Specifically, I want the row to turn gray and then fade out normally.
I have tried selecting the row and then deselecting the row programatically after calling [tableView reloadData], but it doesn't work.
I know that if I was using UITableViewController that I could just call [self setClearsSelectionOnViewWillAppear:NO], but I'm not.
Is there a similar property I can set for UIViewController?
Here is the code:
[tableView beginUpdates];
[counts replaceObjectAtIndex: row withObject: [NSNumber numberWithInt:newCount]];
[tableView reloadData];
[tableView endUpdates];
I feel I may not be describing what is going on. I have a row that uses UITableViewCellStyle2, which displays a label to the left and right. On the right aligned text is a number that increments each time the row is tapped. Simply updating the data structure does not solve the problem. I need to update it visually. I don't need or want to replace the row, unless I have too. I just want to update the right-aligned text field AND keep the row from being deselected immediately without animation. I can do one or the other, but not both.
Is there a way to just update the right-aligned text field while still staying true to the MVC model?
Remove the [tableView reloadData]; from the code. It should not be called in the methods that insert or delete rows, especially within an animation block implemented with calls to beginUpdates and endUpdates .
Call reloadData method to reload all the data that is used to construct the table, including cells, section headers and footers, index arrays, and so on. For efficiency, the table view redisplays only those rows that are visible. It adjusts offsets if the table shrinks as a result of the reload. The table view's delegate or data source calls this method when it wants the table view to completely reload its data.
[tableView beginUpdates];
[counts replaceObjectAtIndex: row withObject: [NSNumber numberWithInt:newCount]];
[tableView endUpdates];
See the developer.apple section - reloadData
If you want to keep the selection after reload, the easy way is
NSIndexPath *selectedRowIndexPath = [tableView indexPathForSelectedRow];
[tableView reloadData];
[tableView selectRowAtIndexPath:selectedRowIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];