I have a view that has several options, and inside it is a table view that gets data from a server.
Is there a way to have the table view automatically select the first option on load, i.e. in viewDidLoad?
Try UITableView's selectRowAtIndexPath:animated:scrollPosition: method.
- (void)viewDidLoad {
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
}
If you want the delegate callback, you'll have to call it manually:
if ([self.tableView.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)])
[self.tableView.delegate tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
You'd probably want to cache that index path in a local variable, then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With