Scrolltorectatindexpath will not be able to scroll to particular section? - ios

I had an application in which i want to scrolltoindexpath to a particular section. I am doing like this
[table scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:anIndex] atScrollPosition:UITableViewScrollPositionTop animated:NO];
[table reloadData];
all working fine.but here the issue is tableview always kept to the bottom .
it won't scroll up after that.it will always keeping the last cell to the bottom.not scrolling up after that.I set the constraints as (0,0,0,0).
I think i miss something here .Can anybody guide me on this?

There are mainly 2 issues here.
1)
[table scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:anIndex] atScrollPosition:UITableViewScrollPositionTop animated:NO];
With animated false, you have to forcefully call dispatch_get_main_queue() even if it's running on main thread. This is supposedly an iOS bug.
2) When you are trying to scroll the tableView, it calls cellForRowAtIndexPath for the available cells. However the immediate next line is calling reloadData which tries to call the same dataSource method. So it might be conflicting with others. So I would recommend adding a small delay for [table reloadData];

Related

UITableView insertRowsAtIndexPaths:WithRowAnimation without freeze UI

I try to understand what is the best practice to use when I work with UITableView with large number of row to insert when the table is visible.
This is my behavior:
I have one UITableView and one Thread that try to insert a data into this table. I think that make a [UITableView reloadData] is a poor solution for the performance aspect, and I know that UIKit operation are be carried on main thread, for this reason when the datasource update is completed I tried to send a NSNotification to make a UITableView update operation (beginUpdate - insertRowAtIndex - endUpdate) on the main thread, but this technique freeze the user interface. I have to work with 1000+ number of rows.
Someone has already solved this problem ? Is it a possible solution the use of GDC async and sync? If yes, how?
Thanks in advance.
Do you try like this:
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView beginUpdates];
[self.tableDatalist insertObject:obj atIndex:index];
[self.tableView insertRowsAtIndexPaths:#[[NSIndexPath indexPathForRow:index inSection:0]]
withRowAnimation:UITableViewRowAnimationRight];
[self.tableView endUpdates];
});

How to delete rows from UITableView without animation in IOS

I have an accordion type of UITableView that works but I just need to adjust the animation slightly. When a row is clicked a method is called that deletes the rows that are showing then adds the new rows to show. I don't want to animate the rows being deleted. I only want to animate the part when the rows are being added. I can use [UIView setAnimationsEnabled:NO]; to turn off the animation all together but I just want to turn it off for the deleting part.
[self.unitListTableView beginUpdates];
[self.unitListTableView deleteRowsAtIndexPaths:delete withRowAnimation:UITableViewRowAnimationTop];
[self.unitListTableView insertRowsAtIndexPaths:added withRowAnimation:UITableViewRowAnimationFade];
[self.unitListTableView endUpdates];
Any help appreciated.
Call reloadData on your table view and it updates without any animation.

When reloading a UITableView section, all sections flash

I'm using a UITableViewController, and am using:
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:sectionNumber] withRowAnimation:UITableViewRowAnimationNone];
to reload an individual section of the tableview (to animate the insertion of new cells). The issue is that all of the sections, and their cells, flash white briefly every time this call is made. This does not occur if I use
[self.tableview reloadData];
but does occur no matter which row animation I use.
I'm aware that I can use insertRowsAtIndexPaths:withRowAnimation:, but I currently have a race condition that doesn't allow me to use that. I will, at some point, fix that, but in the meantime I would like to know why all sections cells flash while I'm reloading a single section. In addition, if I can turn off the flash and just animate the insertion / deletion of cells, that would be ideal.
I believe that it flashes because when you reload a specific section, it still has to recalculate the size of all the visible sections. Hence the flash. Without using insertion/deletion (because it knows the table will only change by one), you can't get past that.
If you are just trying this in the simulator though, it is possible that the flash will either disappear or be less noticeable when loaded on an actual device.
May be it's too late. But it could help someone.
Obj-c:
[UIView performWithoutAnimation:^{
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:[indexPath section]] withRowAnimation:UITableViewRowAnimationNone];
}];
Swift 5:
UIView.performWithoutAnimation {
self.tableView.reloadSections(NSIndexSet(index: indexPath.section), with: .none)
}

deleteRowsAtIndexPaths without animation

I got an app with a UITTableView. This table is updatable. And when in the next update the number of rows are less than in previous version, i implement the UITableView's method - deleteRowsAtIndexPaths.
I do it in this way:
[table beginUpdates];
[table deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
[table reloadRowsAtIndexPaths:indexPathsReload withRowAnimation:UITableViewRowAnimationNone];
[table endUpdates];
But when i implement this code there are animations. And this animation is really bad. A lot of black leaks. But i did write - withRowAnimation:UITableViewRowAnimationNone in both methods: delete and reload.
Why? How can i reload and delete rows without animation?
Usually the way this is done is by modifying the data source of the table, and calling reloadData on the table.
maybe you try to work with NSMutableArray (delete row by removeObjectAtIndex:indexPath.row) in TableView and reload the whole tableview by using [tableView reloadData] ?
You can try to make that "gesture" out of the table,and try reload table
Unlike what the name suggests *UITableViewRowAnimationNone* doesn't help at all.
Maybe setting the alpha on the cell works as suggested here. Not sure though.
problems with animation when deleting the last row of a TableView in ios7

Can not select row in UITableView on iPad

I am working on an iPad app with a split view controller. I have a stock standard UITableView as the master view.
When the view opens, I would like it to select the first row in the list.
In ViewDidLoad I have:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
When I run the app in the simulator it seems to select the first row (flashes) but then it is no longer selected. It is like something is clearing the selection after the ViewDidLoad method. I can touch and select rows just fine. Is there a property on the row or the prototype cell I need to set for this to work correctly?
Thanks in advance,
Richard
Try doing that in the viewDidAppear instead of viewDidLoad.
Edit:
Just one thing Richard, this works because when you actually enter in the viewDidAppear your UITableView has been fully reloaded. In case it hasn't, it wouldn't work. You can actually do something like this, which I recommend (check the comment from Eric Morand).

Resources