Green Developer Green Developer - 1 year ago 71
iOS Question

UITableView Automatically Select Row

When a

loads, I want the only row, in the only section, to be selected so that the code in the
will execute immediately when the user loads the
. I've tried the code below but it doesn't execute the code in the
section. Any thoughts?

NSIndexPath *indexedPath = [NSIndexPath indexPathForRow:0 inSection:0];
[tableView selectRowAtIndexPath:indexedPath animated:YES scrollPosition: UITableViewScrollPositionNone];

Answer Source

Make use of this code.This will Automatically call didSelectRowAtIndexPath when the view is loaded.

  [self tableView:tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];