iRam11
iRam11

Reputation: 307

How show selected row when click on table view?

I have a button. When click on button then open a table view with 100 row. I user select a ny row then appear check mark. And when user click on again then i want to show that selected row when view open. How do that? For example when user click on button then open table view and suppose select 50 th row. Now user click on button again then i want to show 50th row directly instead user go to scrolling table view. So tell me how do that? Thanks in advance..

Upvotes: 0

Views: 973

Answers (2)

EmptyStack
EmptyStack

Reputation: 51374

Use,

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:selectedRow
                                            inSection:sectionOfSelectedRow];
[tableView scrollToRowAtIndexPath:indexPath animated:YES];

Upvotes: 3

Nekto
Nekto

Reputation: 17877

Just call

- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition

to your table view.

For example, following code will select 50th row in first section:

UITableView *tableView;
[tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:50 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];

Upvotes: 4

Related Questions