在视图出现之前进行UITableView选择 [英] Make UITableView selection before view appears

查看:60
本文介绍了在视图出现之前进行UITableView选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为UITableView构建详细视图.详细信息视图包含一个具有两行的UITableView,我希望在打开详细信息视图时选择第一个.我试图在 [viewWillAppear] 中使用方法 [selectRowAtIndexPath:animated:scrollPosition] :

I'm building a detail view for a UITableView. The detail view contains a UITableView which has two rows, and I want the first one to be selected when the detail view is opened. I have tried to use the method [selectRowAtIndexPath:animated:scrollPosition] in [viewWillAppear]:

- (void) viewWillAppear:(BOOL)animated {  
    [[self tableView] selectRowAtIndexPath:[NSIndexPath indexPathForRow:kStartDateRow inSection:kSection]  
                                  animated:NO  
                            scrollPosition:UITableViewScrollPositionNone];  
}

但是,选择不受此影响,并且在 [viewDidAppear] 中使用它意味着一旦视图移到适当位置,选择就会更改.如何在细节视图出现在屏幕上之前进行选择?

However, the selection is not affected by this, and using it in [viewDidAppear] means the selection changes once the view has moved into place. How can I make the selection before the detail view appears on screen?

您可以在设置"应用中查看我想要的行为的示例.转到常规>日期和时间;时间>设置日期和时间时间.

You can see an example of the behaviour I want in the Settings app. Go to General > Date & Time > Set Date & Time.

推荐答案

您没有提到任何错误,但请尝试在selectRowAtIndexPath行之前进行[[self tableView] reloadData].

You don't mention any error but try doing [[self tableView] reloadData] before the selectRowAtIndexPath line.

这篇关于在视图出现之前进行UITableView选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆