【问题标题】:Go to specific tab bar views转到特定的标签栏视图
【发布时间】:2013-01-14 22:01:35
【问题描述】:

我的应用启动时有 6 个视图控制器。它就像一个图片库。例如,当用户按下第三个视图上的按钮时,他/她应该进入选项卡栏中的第三个视图。

我使用这段代码来启动标签栏控制器顶部的视图控制器:

- (void)viewDidAppear:(BOOL)animated {
    static BOOL first = YES;
    if (first) {
        UIViewController *popup = [[Home1ViewController alloc] initWithNibName:@"Home1ViewController" bundle:nil];

        [self presentViewController:popup animated:NO completion:nil];
        first = NO;
    }
}

通过使用此代码关闭这个新视图,我只是进入特定视图,而不是我的标签栏页面...

-(IBAction)dismissView {
    TabBarPage3 *screen = [[ TabBarPage3 alloc] initWithNibName:nil bundle:nil];
    screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:screen animated:YES];
}

请帮帮我! 谢谢

【问题讨论】:

  • 你的意思是你想去UITabbar的第三个视图??如果是,您可以使用 [tabbar setSelectedIndex:index];方法
  • 好的,我可以这样用吗? -(IBAction) {[tabbar setSelectedIndex:index]; };
  • 是的。它适用于我的项目。 [tabbarName setSelectedIndex:index]
  • 其实这可能更好:) [((UITabBarController *)(self.parentViewController))setSelectedIndex:index];只需到达您的父视图然后转换为 UITabBarController 然后使用 setSelectedIndex 方法

标签: ios xcode view controller


【解决方案1】:

这是在 TabBar 上更改视图的代码

[((UITabBarController *)(self.parentViewController))setSelectedIndex:index];

Sample Project of UITabbar

【讨论】:

  • 有趣。它对我有用。您是如何提出您对 UITabBar 的第一个看法的?
  • - (void)viewDidAppear:(BOOL)animated { static BOOL first = YES; if (first) { UIViewController *popup = [[Home1ViewController alloc] initWithNibName:@"Home1ViewController" bundle:nil]; [self presentViewController:popup animated:NO completion:nil];第一个=否; } }
  • 我认为错误的部分是您直接打开视图。只需创建一个标签栏并将其作为第一个视图放入。我为你写了一个示例代码。我将上传到网络上的某个地方,您可以下载并检查代码。就像我说的,你应该直接创建标签栏而不是第一个视图
  • 你上传了吗?
  • 答案上有一个链接。点击帖子上的“UITabbar示例项目”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-25
  • 1970-01-01
  • 2012-10-09
  • 1970-01-01
相关资源
最近更新 更多