I've used reloadRowsAtIndexPaths: on iOS 6, and it ran fine.
[self.tableview beginUpdates];
[self.tableview reloadRowsAtIndexPaths:indexPath withRowAnimation:UITableViewRowAnimationNone];
[self.tableview endUpdates];
This calls cellForRowAtIndexPath: of the tableview on iOS 6, but, it doesn't call cellForRowAtIndexPath: of the tableview on iOS 7, so I can't update the specified cell.
Related
I have UITableview which has dynamic row height using AutoLayout.
In iOS 8.4, if set scrollToRowAtIndexPath or setContentOffset its not scroll to last indexpath. in iOS 9.x it is working. Kindly help
[tableview scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:arr.count - 1 inSection:RootArr.count - 1] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
dispatch_after(0, dispatch_get_main_queue(), ^{
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
});
It is OK
I have a UITableView which I have hooked up to a NSFetchedResultsController. When an object is updated, I use reloadRowsAtIndexPaths to reload the cell. I want to keep the cell selected while it is reloaded. The below code is how I am reselecting the cell after the update. It works, but the cell displays unselected for about half a second before becoming selected again and looks bad. self.selectedIndexPath is set in didSelectRowAtIndexPath.
I've also tried setting the cell to selected and highlighted in cellForRowAtIndexPath, but that did nothing.
Does anyone know how to prevent the flickering? I'm using iOS 8.3 BTW.
// Called in controllerWillChangeContent
[self.tableView beginUpdates];
...
// Called in didChangeObject
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
...
// Called in controllerDidChangeContent
[self.tableView endUpdates];
if( self.selectedIndexPath ) {
[self.tableView selectRowAtIndexPath:self.selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}
I have aUITableView with delegate methods declared. ThenumberOfRows &numberOfSections are updated dynamically.
(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section{}
(NSInteger)numberOfSectionsInTableView:
Instead of using the [tableView reloadData], I would need to usereloadRowsAtIndexPath.
However I get a crash with invalid number of rows. How do I handle the dataSource changes? Lets says I have an array of count 10, and when I reload theUITableView usingUIRefreshControls by pulling, and the data from the server. From 10, if the count of array drops to 1, how will I handlereloadRowsAtIndexPath?
[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathForVisibleRows] withRowAnimation:UITableViewRowAnimationNone]
There seems to be a crash when this is called. How would I handle change in data array's count?
To reload specific cells of Tableview the method is reloadRowsAtIndexPaths: not reloadRowsAtIndexPath
[self.tableview reloadRowsAtIndexPaths:[self.tableview indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];
However for reloadRowsAtIndexPaths to work properly datasource needs to be consistant. As Indexpaths are already loaded.
If you still use this method, You will get either arrayIndexOutofBound error or duplicate values in cells(depending on increase or decrease in datasource).
//call begin and end updates while performing some hard core actions on tableview
[My_Table beginupdates];
[My_Table reloadRowsAtIndexPaths:[My_Table indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];
[My_Table endupdates];
hope it will helps you.
you can try with this.
[tblMe beginUpdates];
[tblMe reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:0 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
[tblMe endUpdates];
Hope this may help !!!
I have the following code in tableView:didSelectRowAtIndexPath:
[tableView reloadData];
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
It deselects a table view cell tapped by the user (with animation) after the table view is reloaded. It has worked fine in iOS 7 and earlier, but in iOS 8 the animation isn't shown.
What changes were made in iOS 8 to cause this? And what's the best way to achieve the same effect in iOS 8?
What is the surrounding code that's causing you to call [tableView reloadData]?
Depending on how much processing you are doing in cellForRowAtIndexPath and the surrounding methods, this can be an expensive operation.
You can run:
[tableView beginUpdates];
// Update code here
[tableView endUpdates];
without having to reload the entire tableView datasource.
When didSelectRowAtIndexPath is called, the cell is already selected. So there shouldn't be any need to call the tableView's selectRowAtIndexPath method. Simply calling deselectRowAtIndexPath should do the trick after updating your cells
I change the height of a cell (when image downloaded) with method like that
-(void)didHeightChanged:(float)imageHeight atIndex:(NSInteger)indexPath
{
[dictionary setObject:imageHeight forKey:indexPath];
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
Everything works well with first data, but when I reload UITableView with second data , probably beginUpdates method doesnt ended and I got issues - when I delete and reload UITableView, cell dont disappear, UITableView shows wrong cells
How can I stop beginUpdates immediately before reload new data?
You should either call [self.tableView reloadData] or [self.tableView reloadRowsAtIndexPaths:#[[NSIndexPath indexPathWithRow:index inSection:0]]]; // or indexPath if instead of passing a NSInteger you pass a NSIndexPath * to the method.
I found the answer
[self.tableView beginUpdates];
[self.tableView endUpdates];
it was called in background thread...