Set first cell to highlighted on view's load
I have a UISplitViewController. When the app launches initi开发者_如何学编程ally, the detail view is showing the detail data for the first row. However, the cell in the table is not highlighted, since it hasn't been selected yet. How can I set it to selected by default when the app loads initially?
I added this to cellForRowAtIndexPath
but its not highlighting. It highlights fine when I actually select a cell.
if (indexPath.row == 0)
{
cell.selected = YES;
}
-(void)selectFirstRow {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
// optional:
// [self tableView:myTable willSelectRowAtIndexPath:indexPath];
[myTable selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
// optional:
// [self tableView:myTable didSelectRowAtIndexPath:indexPath];
}
Then call [self selectFirstRow];
wherever you need to.
精彩评论