我有一个应用程序与UITabBarController,其中第一个选项卡包含一个主页的ViewController。我必须做的是在标签之间切换(这很简单:[[self tabBarController] setSelectedIndex:index]),AND从“HomePage”中通过selectedTab的出口导航。如何以编程方式在UITabBarController之间切换
只是为了解释自己:TabElement1 ---> TabElementX ----> UISegmentedController:segmentY
的问题是,UISegmentedController是零,因为它尚未初始化(至少是我第一次做操作)。我应该如何解决这个问题?选项卡元素装有笔尖。
EDIT--下面是一些代码:
@implementation HomeViewController // Tab Indexed 0
// ...
- (void)playVideoPreview {
NSArray *array;
array = [[self tabBarController] viewControllers];
// This is a test where I programmatically select the tab AND the switch.
[[[array objectAtIndex:2] switches] setSelectedSegmentIndex:1];
[[self tabBarController] setViewControllers:array];
}
@end
@implementation TGWebViewController // Tab Indexed 2
// ...
@synthesize switches; // In .h file: @property (nonatomic, retain) IBOutlet UISegmentedControl switches; Properly linked within the XIB.
- (IBAction)switchHasChangedValue {
// Foo operations.
}
现在我第一次开火playVideoPreview我设法进入选项卡索引2,TGWebViewController,但交换机还不存在,所以我发现我自己分段控件名为“开关”,并选择第一个段。如果我回到HomeViewController,然后再次播放playVideoPreview,我会得到正确的行为。
你在哪里有这样的代码,其中UISegmentedCOntrol是零?在viewDidLoad中,viewWillAppear或App Delegate本身? – Ladislav 2011-03-01 10:18:15
我会粘贴一些代码让你理解。 – IssamTP 2011-03-01 10:46:24