简体   繁体   English

将第一个单元格设置为在视图加载时突出显示

[英]Set first cell to highlighted on view's load

I have a UISplitViewController. 我有一个UISplitViewController。 When the app launches initially, 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. 我将此添加到cellForRowAtIndexPath但未突出显示。 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]; 然后调用[self selectFirstRow]; wherever you need to. 无论您需要在哪里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM