从 ModalViewController 中选择第二个选项卡
在我的应用程序委托中,我在选项卡栏顶部加载了一个视图控制器。该控制器上有三个按钮,一个用于导航到每个选项卡。当按下第二个按钮时,我想关闭视图控制器并转到第二个选项卡。但这似乎并不按正常方式工作。
我的 AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//-- Insert a delay of 5 seconds before the splash screen disappears
[NSThread sleepForTimeInterval:3.0];
// Set the tab bar controller as the window's root view controller and display.
self.window.rootViewController = self.tabBarController;
// Set StartView to load first
StartViewController *startViewController = [[StartViewController alloc] initWithNibName:@"StartView" bundle: nil];
[window addSubview: [startViewController view]];
[window makeKeyAndVisible];
[self.tabBarController presentModalViewController:startViewController animated:NO];
[startViewController release];
return YES;
}
这是我当前的 IBAction,它似乎不起作用:
- (IBAction) toSecondView:(id)sender
{
// Show status bar
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[(UITabBarController *)self.parentViewController setSelectedIndex:1];
[self dismissModalViewControllerAnimated:NO];
}
我也尝试了这些,但没有成功:
self.tabBarController.selectedIndex = 1;
任何人都
[self.tabBarController setSelectedIndex:1];
可以帮助我并解释我所缺少的内容吗?
In my app delegate I load a view controller on top of my tabbar. This controller had three buttons on it, one to navigate to each tab. When the second button is pressed, I want to dismiss the view controller and go to the second tab. But this doesn't seem to work the normal way.
My AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//-- Insert a delay of 5 seconds before the splash screen disappears
[NSThread sleepForTimeInterval:3.0];
// Set the tab bar controller as the window's root view controller and display.
self.window.rootViewController = self.tabBarController;
// Set StartView to load first
StartViewController *startViewController = [[StartViewController alloc] initWithNibName:@"StartView" bundle: nil];
[window addSubview: [startViewController view]];
[window makeKeyAndVisible];
[self.tabBarController presentModalViewController:startViewController animated:NO];
[startViewController release];
return YES;
}
And here is my current IBAction, which doesn't seem to work:
- (IBAction) toSecondView:(id)sender
{
// Show status bar
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[(UITabBarController *)self.parentViewController setSelectedIndex:1];
[self dismissModalViewControllerAnimated:NO];
}
I tried these too, without success:
self.tabBarController.selectedIndex = 1;
and
[self.tabBarController setSelectedIndex:1];
Can anyone help me out and explain me what I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生这种情况有以下原因。
您已将 ViewController 作为子视图添加到窗口中,无需添加 SubView,因为您已经将该 ViewController 呈现为 ModalViewController。
请尝试如下。
}
}
This happend because a below of reason.
You have added ViewController Onto the Window As a subView, no need to add SubView because you are already presenting that ViewController as ModalViewController.
Please Try as below.
}
}