IPad: saving the selected cell of the lookup table on the screen

On iPad, I show UIPopoverwhen the user selects cells in UITableView. The cell remains selected until the popover is rejected.

When the user rotates the device from portrait to landscape orientation, and the selected cell is at the bottom of the screen, it disappears after the rotation, and the popover ends, pointing to another (indifferent) cell.

How can I make sure that the selected cell in UITableViewremains on the screen when I rotate from portrait to landscape?

Update: Combining the Caleb and kviksilver codes, the following working solution:

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    CGRect activeCellRect = [self.tableView rectForRowAtIndexPath:self.indexPath];
    if ((activeCellRect.origin.y + activeCellRect.size.height) >
        (self.view.frame.origin.y + self.view.frame.size.height))
    {
        // If a row ends up off screen after a rotation, bring it back
        // on screen.
        [self.tableView scrollToRowAtIndexPath:self.indexPath
                              atScrollPosition:UITableViewScrollPositionBottom
                                      animated:YES];
    }
}

2 UIPopover:. reloadData . rectForRowAtIndexPath: ( , )!

+3
2

indexPathsForVisibleRows, , , scrollToRowAtIndexPath, .. - :

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    if (![[self.tableView indexPathsForVisibleRows] containsObject:[self.tableView indexPathForSelectedRow]]) {
        [self.tableView scrollToRowAtIndexPath:[self.tableView indexPathForSelectedRow] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
    }
}
+4

, , ? , , , , , UIViewController. , UITableView -rectForRowAtIndexPath:, , UIScrollView -scrollRectToVisible:animated:, UITableView .

+2

All Articles