【问题标题】:xcode tab bar controller change selected item with codexcode标签栏控制器用代码更改所选项目
【发布时间】:2014-10-27 13:34:53
【问题描述】:

首先,我使用的是 Xcode 6 和 Objective-c。我想用按钮或用代码自动更改标签栏屏幕我该怎么做。另一个问题可能是我做这个不同的视图而不是标签栏控制器的项目。

- (IBAction)backButton:(id)sender
{
    ProfileSide *vc = (ProfileSide *)[[self.tabBarController viewControllers]objectAtIndex:1];
    [vc.view setNeedsDisplay];
    [self.tabBarController setSelectedViewController:vc];
}

我尝试了此代码部分但无法正常工作。 ProfileSide 类第 3 项标签栏控制器的名称。

ProfileSide *vc1 = [self.storyboard instantiateViewControllerWithIdentifier:@"meScreen"];
[self presentViewController:vc1 animated:YES completion:nil];

也有这个代码部分,但是当我使用这个标签栏时会消失。

【问题讨论】:

  • 首先是的可以做到这一点...另一个,向我们展示您到目前为止所做的尝试...
  • 编辑了我的问题,您可以查看
  • 仅当您在视图的-drawRect: 方法中执行自定义绘图时才调用-setNeedsDisplay,并且该视图需要重绘其视图。
  • ProfileSide *vc = (ProfileSide *)[[self.tabBarController viewControllers]objectAtIndex:1]; [vc.view setNeedsDisplay]; 当我再次这样运行时不起作用

标签: ios objective-c xcode


【解决方案1】:
[self.tabBarController setSelectedIndex:yourIndex];

【讨论】:

  • 你的代码比我创建 UITabBarController 类和我使用 self.selectedIndex = 3; 这个代码部分现在工作...
猜你喜欢
  • 2020-07-29
  • 2011-09-25
  • 2014-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多