Search code examples
iphoneipaduitableviewrowhighlight

Programmatically highlight first row in tableview after first load


Im trying to highlight the first row in my table upon first loading the data and just cannot get it to work!

I have tried lots of ways with no joy, the latest attempt being this:

NSUInteger indexArr[] = {0,1};

NSIndexPath *n = [NSIndexPath indexPathWithIndexes:indexArr length:2];

[self.tableView scrollToRowAtIndexPath:n atScrollPosition:UITableViewScrollPositionTop animated:NO];

Solution

  • try

    [self.tableView selectRowAtIndexPath:n animated:YES scrollPosition:UITableViewScrollPositionTop];
    

    you should probably do this after your view has appeared.