Khoi Nguyen
Khoi Nguyen

Reputation: 147

Select first row in tableview at default and fire didselect when load view

When the view is load, the tableview will select the first row and it fire the didselectatrow method to do something. I've just know how to select the first row but it not fire the didselectatrow method at a same time Show me how to do like that

Upvotes: 0

Views: 1693

Answers (1)

jszumski
jszumski

Reputation: 7416

You can just call the method manually in viewDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];

    // select the first row
    NSIndexPath *firstRowPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableView selectRowAtIndexPath:firstRowPath animated:NO scrollPosition: UITableViewScrollPositionNone];
    [self tableView:self.tableView didSelectRowAtIndexPath:firstRowPath];
}

Upvotes: 5

Related Questions