Praveen
Praveen

Reputation: 45

UITableview scrolling postion on didselectrow

I have a UITableView which consist of Chapters and Subchapters. On selecting Chapters the respective Subchapter will expand in UITableView. When I click the last Chapter the subchapter is not visible in the screen. Have to scroll below automatically when the subchapters appear.

Upvotes: 0

Views: 73

Answers (2)

Javito_009
Javito_009

Reputation: 40

On didSelectRowAtIndexPath method you need something like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
...
    [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
    CGRect sectionRect = [tableView rectForSection:indexPath.section];
    [tableView scrollRectToVisible:sectionRect animated:YES];
...
}

Hope it helps.

Upvotes: 0

iHulk
iHulk

Reputation: 4909

You can either use

[self.table scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];

Or use

CGPoint bottomOffset = CGPointMake(0, yourTableView.contentSize.height - yourTableView.frame.size.height);
[table setContentOffset:bottomOffset]

This will scroll the tableView to the bottom when a new cell will be inserted to your tableView

Upvotes: 1

Related Questions