Reputation: 45
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
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
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