I have very custom TableView like Add Contact View in iPhone's Contacts.
I like the way this view arrange rows in animation when I click Edit button.
My table view has for example 2 rows of editable information and 6 rows non-editable.
I wrote some code and this 6 non-editable rows disappear from screen when user click my custom Edit button. But its very "flat" and not interesting. Its just remove rows and reloadData then;
I want to add some nice animation in process of removing cell and appearing back after "Done" click.
I can't use standard "setEditing animated" because my view custom and I don't need insert or delete rows - i just edit information in it;
Thanks :)
oh i think i found it in documantation )
[tv beginUpdates];
[tv insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationRight];
[tv deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];
[tv endUpdates];
Related
I have a UITableView, that add's some data after the UITableView reloaded for the first time, but I can't scroll down to the new data if I scroll I see the new data but then it scrolls back automatically, and yes I reloaded my UITableView, so I checked my UITableView contentSize and it won't change after the reload but after I go to another view (UINavigationController) and pop back the UITableView contentSize does change and it works! How can I fix this?
Thanks!
I had a similar issue and solved it using the same technique as Daan (as far as I can tell).
In my case I was using a static UITableView that had some of its rows and sections hidden initially (by setting appropriate return values from numberOfSectionsInTableView: and tableView:numberOfRowsInSection:). I was pushing a VC onto the nav stack to collect additional data which I would then use to fill in the hidden tableview sections, calling reloadData on the tableview to refresh it.
This worked fine in iOS7, but in iOS6 the tableview's contentSize.height never changed from its initial value (218 pts) to the taller value (504 pts) derived from the addition of the new sections. As such, you could not scroll to the content at the bottom of the tableview. Trying to force the contentSize did not work as it was immediately set back to 218.
Changing the tableView's contentOffset allowed me to scroll to the bottom of the content, but if you tapped the UITextField in the last cell, it would whip off screen as the keyboard was shown.
I finally was able to come up with a solution that worked in both iOS6 and iOS7 without issue. I used the old beginUpdates / insert or delete rows and sections / endUpdates methods of UITableView, as follows:
// change the tableView's data source to reflect insertions/deletions
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:#[ [NSIndexPath indexPathForRow:1 inSection:0] ] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView insertSections:[NSIndexSet indexSetWithIndexesInRange:NSRangeFromString(#"1,3")] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
As you can see, in this particular case I had to remove a row from the first (and only) section and add three sections to the end of the tableview.
I am currently building a UITableView that reads an array and displays it on a TableView. I am continually adding to the array I would like to have a button on the view that once is clicked it updates the UITableView.
How do I implement a reload of the UITableView from the new array I just built?
If you are adding and removing items one to a few at a time you will likely want to implement the animated table view methods for insertion and deletion.
When you add or remove an item from the table view you will prepare by calling [tableView beginUpdates] make your array modifications and then call [tableView endUpdates]
Between the begin and end update calls you will perform the actually deletion/insertion.
For deletion you should use
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
Notice UITableViewRowAnimationBottom you will want to play around with this to get the best animation depending on the position of the element. Also iOS5 has a enum value something like UITableViewRowAnimationAutomatic and it will use the best option.
For insertion you should use
insertRowsAtIndexPaths:withRowAnimation: the same way I show above with delete.
For more info check out the section with these methods listed in the UITableView class reference
The function you're looking for is [self.tableView reloadData];. Here's a link to the Apple documentation for UITableView.
I have a UITableView , in which if I tap on one of the rows it adds a subview at the bottom. The issue is that when I tap the last row in the table, it hides the subviews and having me to scroll to the bottom to see it. It's a small bug, but what is the best way to remedy this issue.
One way I can think of is to scroll down to the bottom of the row if the last row is selected.
This doesn't seem to be a very good solution though.
Here's a video illustrating my issue
You may want to try something like this in the didSelectRow method:
if (indexPath.row == [dataArray count]) {
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row
inSection:0]
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
}
I've also used the following for making the last row visible (though from your video I do not think this will work for your situation)
[guessesTableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
I looked for this problem and I don't believe I could find an answer. I have a tableview of custom cells that when clicked, the selected cell pushes a new cell with information. I was wondering if anyone had an idea of how to push the selected cell to the top of the uitableview, or make it fill up the entire tableview.
My uitableview only takes up half of the screen, and I wish for when the cell is selected that it only take up that half of the screen, and the user is still able to scroll the cell (if that makes sense)?
Any suggestions would be appreciated, it was somewhat difficult to describe what I am looking for, so if anyone needs clarification please do not hesitate to ask me.
in cellForRowAtIndexPath, you need to place this in after you have created your cell
[tableView scrollToRowAtIndexPath:selectedCellIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
This did the trick for me with the custom height of the cells as well.
In my app I have a bunch of cells that expand to be larger when clicked; and only 1 cell can be expanded at a time. I basically keep track of the current selected indexPath, and then in heightForRowAtIndexPath: check to see if this is the selected sell; if it is I return a larger height.
Then, in didSelectRowAtIndexPath: I just set the current indexPath, and reload both the new cell and the previous one. This sounds similar to what you are looking for... would that work?
To move the selected cell to the top of the tableview, you could store the selected cell's index in an instance variable in didSelectRowAtIndexPath, and then call [tableView reloadData].
In your datasource's tableView:cellForRowAtIndexPath: method, you would ensure that the selected cell is returned for index 0 and all cells prior to the selected cell are returned for their index + 1.
If you are looking to move the cell, this is a base you could start from.
-(void)moveIndexPathToTop:(NSIndexPath *)pathToMove
{
[myTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:pathToMove] withRowAnimation:UITableViewRowAnimationFade];
NSIndexPath *firstRow = [NSIndexPath indexPathForRow:0 inSection:0];
[myTable insertRowsAtIndexPaths:[NSArray arrayWithObject:firstRow] withRowAnimation:UITableViewRowAnimationFade];
}
This will move the row as far as the UITableView is conserned. Of course you'll need to match the new order in the data source also. (Like changing the order in your array of data)
Also, you'll probably want to scroll the table to the top when you do this.
I have a tableview with one sectionheader. With the following codesnippet I reload the tableview when a user swipes the view left or right.
[self.tableView beginUpdates];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView endUpdates];
When a user has scolled downwards in the tableview and then swipes, this codesnippet reloads the rows correctly but the sectionheader is created on top of the row where the swipe was initiated.
Can anyone tell me what I'm doing wrong & how to solve ?
thanks
Frank
I think the problem is that reloadSections:withRowAnimation seems to be buggy on iOS 4.0, and it was fixed in one of the later versions.
On iOS 4.0 calling reloadSections:withRowAnimation results in table header appearing in the middle of a row, and on 4.3 it works fine. I've replaced it with reloadData which is less optimal, but works on 4.0 too.