开发者

Set first cell to highlighted on view's load

开发者 https://www.devze.com 2023-04-10 03:54 出处:网络
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 i

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消