iphone - 将第一个单元格设置为在 View 加载时突出显示

标签 iphone objective-c cocoa-touch uitableview

我有一个 UISplitViewController。当应用程序最初启动时,详细信息 View 将显示第一行的详细数据。但是,表中的单元格未突出显示,因为尚未选择它。如何在应用程序首次加载时将其设置为默认选择?

我将其添加到 cellForRowAtIndexPath 但它没有突出显示。当我实际选择一个单元格时,它会突出显示。

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];
}

然后在任何需要的地方调用[self selectFirstRow];

关于iphone - 将第一个单元格设置为在 View 加载时突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7642022/

相关文章:

objective-c - 相似的代码行,截然不同的性能

objective-c - 如何找出谁调用了方法?

iphone - 我的 NSXMLParser 没有解析并返回 null

iphone - 在 iOS 媒体播放器 Controller 中禁用全屏模式

ios - 添加了 insertRowsAtIndexPaths 的 UITableView 单元格未正确绘制/布局

ios - iOS分发推送通知是否需要设备 token

ios - 具有自动布局的UISegmentedControl会错位标题

ios - 在 ios 中为标签制作抖动效果?

iphone - 如何自定义UIAlertView?苹果会批准吗?

iphone - 如何从 UIWebview 或 dealloc UIWebview 中删除缓存