I am creating an application with a UITableView
being the first item on the stack of the UINavigationController
that it's in. Making a selection on the UITableView
will push the view to a "DetailedViewController
". In the DetailedViewController
, you can navigate through items that the table view is populated with.
When p开发者_如何学Copping the DetailedViewController
, and moving back to the UITableView
, how can I deselect the respective item that I've navigated to through the DetailedViewController
and display it centered in the UITableView
?
An example that everyone can see would be the Mail application. When you're in your inbox and make a selection, you push a "DetailedViewController
". There, you can navigate through the items populated in the UITableView
. When you pop the DetailedViewController
, it deselects the respective item that you were looking at last in the DetailedViewController
.
To deselect the selected row, write the following code viewDidAppear:
method.
// Index path for selected row
NSIndexPath *selectedRow = [_tableView indexPathForSelectedRow];
// Deselet the row with animation
[_tableView deselectRowAtIndexPath:selectedRow animated:YES];
// Scroll the selected row to the center
[_tableView scrollToRowAtIndexPath:selectedRow
atScrollPosition:UITableViewScrollPositionMiddle
animated:YES];
Depending on how you want the animation to look you could simply deselect your currently selected row.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
...
}
精彩评论