【发布时间】:2012-02-10 08:03:46
【问题描述】:
我有一个应用程序,它有两个视图控制器 Viewcontroller 和 OptionsViewController。 Viewcontroller 是初始的 viewcontroller,然后如果我点击一个按钮,我就有一个到 optionsviewcontroller 的模态 segue。
在 optionsviewcontroller 中,我有 UISegmented viewcontroller 从故事板创建,它链接到一个插座 (UnitsSegmentedControl),我希望能够告诉分段控件,当 OptionsViewController 加载时,默认情况下应该选择哪个段。
在我的 Viewcontroller 中我写了一个方法:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
OptionsViewController *ovc=[segue destinationViewController];
ovc.delegate=self;
[ovc.UnitsSegmentedControl setSelectedSegmentIndex:1];
}
问题是当 OptionsViewController 加载视图时,默认情况下选定的索引为 0。我没有收到任何错误消息或其他东西。
我使用的是 Xcode 4.2。我认为这可能是我可以在情节提要中更改的一些选项,以使 UISegmentedControl 能够设置默认选定索引。我不知道还有什么可能导致这种情况。
编辑: 我发现如果我写:
[ovc.UnitsSegmentedControl setSelectedSegmentIndex:1];
在 OptionsViewController 方法 viewdidload 中一切正常。为什么我无法通过 prepare for segue 方法做到这一点?
【问题讨论】:
标签: ios5 xcode4.2 storyboard uisegmentedcontrol