scrolling uitableview dynamically - iphone

I want to make a 'UiTableView' which scolls its cells dynamically to the down direction or up direction with and add the next cells to the tableview from the array.
Please suggest me good example over this.
Thanks Neha

here you go:
- (IBAction)clickAction:(id)sender
{
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
[tableView reloadData];
}
or :
// (change n to whatever you like)
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:n inSection:0];
[self.tableView scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionTop
animated:YES];
if you need something more complex let us know.

In this snippet you can scroll and select row table even if rows has not been loaded.
- (void)viewDidAppear:(BOOL)animated
{
NSIndexPath *index = [NSIndexPath indexPathForRow:idx inSection:0];
[_table selectRowAtIndexPath:index animated:YES
scrollPosition:UITableViewScrollPositionMiddle];
}

Related

Animate the newly added row in the table

Is it possible to get IndexPath currently inserting new row into a table. The table data is loaded through the Core Data. The datas are sorted through the sections.
I would like to make a new added row to the table to be animated as shown in the following picture link.
http://i45.tinypic.com/2ykjj7n.png
You can use following method:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
The code is tested, and will definitely work for you...
What about this? Is this what you want to gather? I am not sure.
[yourTableView beginUpdates];
[yourTableView moveRowAtIndex:firstStateIndex toIndex:endStateIndex];
[yourTableView endUpdates];
Of course you have to insert the specific row at first so that you can move it afterwards. The animation could happen like this.
[tblMainView beginUpdates];
[tblMainView reloadRowsAtIndexPaths:<#(NSArray *)#> withRowAnimation:UITableViewRowAnimationLeft];
[tblMainView endUpdates];

Is there a way that a table view pops up when i select a row in a table?

Is there a way that a UITableView pops up when i select a row in a table?
thanks in advance.
In your UITableView delegate method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
[self.view addSubview:myView];
}
Here, myView is the view which you have IBOutlet.
like
in .h file
IBOutlet UIView *myView;
Let me know in case of any difficulty.
Cheers.
Yes there is a way on row selection method you have to fire up a method which creates auiview smaller in size as desired and in that view table view as subview.
Plz specify what type or kind of pop-up you want to appear.
OK, I understand now.
You should use table view's updating methods:
[myTableView beginUpdates];
NSArray *indexPaths = [NSArray arrayWithObjects:
[NSIndexPath indexPathForRow:0 inSection:1],
[NSIndexPath indexPathForRow:1 inSection:1],
[NSIndexPath indexPathForRow:2 inSection:1],
[NSIndexPath indexPathForRow:3 inSection:1],nil];
[myTableView insertRowsAtIndexPaths:indexPaths withRowAnation:UITableViewRowAnimationTop];
[myTableView endUpdates];

How do you scroll to the bottom of a tableView if you don't know how many rows it has?

I know that we can scroll to the bottom of the UITableView in a regular UITableViewController by using:
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated
Where indexPath can be found by doing a count of how many objects are there in the array of objects. However, in three20.. how do we do the same thing as we don't have the array of objects in the table?
I don't know if there's something that makes three20 different, but this should work in any UITableViewController subclass:
- (void)scrollToBottom {
NSInteger section = [self.tableView numberOfSections] - 1;
NSInteger row = [self.tableView numberOfRowsInSection:section] - 1;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
[self.tableView scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionMiddle
animated:YES];
}

Programmatically highlight first row in tableview after first load

Im trying to highlight the first row in my table upon first loading the data and just cannot get it to work!
I have tried lots of ways with no joy, the latest attempt being this:
NSUInteger indexArr[] = {0,1};
NSIndexPath *n = [NSIndexPath indexPathWithIndexes:indexArr length:2];
[self.tableView scrollToRowAtIndexPath:n atScrollPosition:UITableViewScrollPositionTop animated:NO];
try
[self.tableView selectRowAtIndexPath:n animated:YES scrollPosition:UITableViewScrollPositionTop];
you should probably do this after your view has appeared.

Make UITableView go to top line

I sometimes reload table data and I need to redraw the table so that I see the data from the first row again. What I do now is the following:
NSIndexPath *ip = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView selectRowAtIndexPath:ip animated:NO scrollPosition:UITableViewScrollPositionTop ];
[self.tableView deselectRowAtIndexPath:ip animated:NO];
This is not ideal because there is an annoying flash when row 0 is selected and immediately deselected.
How can I fix this?
You can use UITableView's scrollToRowAtIndexPath:atScrollPosition:animated: method.
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
If you have a header that is in view by default, and want to compensate if the action is called when the list is in motion use:
[tableview setContentOffset:CGPointMake(0.0, 0.0) animated:NO];
Short, simple, effective.
You can set contentoffset of tableview to (0.,0.).