带有NavigationController的TabBar

时间:2013-08-06 20:42:22

标签: xcode uinavigationcontroller uitabbarcontroller uitabbar navigationcontroller

实际上我有使用NavigationController的应用程序(带有故事板的Xcode 4.6.2)。我可以根据标准NavigationController提供的功能以及滑动手势来导航下一个/后一个视图。

不,我正在尝试添加标签栏(最后它将是自定义UI元素),这将允许我更改视图。例如,我想在没有滑动手势的情况下从第一个视图跳到第三个视图,但只能通过我底部菜单上的选项卡。 我已经厌倦了添加TabBarController(在Xcode Editor中 - > Embed In - > Tab Bar Controller),但之后我的所有视图导航栏都消失了。

您有什么建议我应该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您可以使用uiswipegesturerecognizer,如此......

- (void)viewDidLoad
{
[super viewDidLoad];

UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tappedRightButton:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.view addGestureRecognizer:swipeLeft];

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tappedLeftButton:)];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[self.view addGestureRecognizer:swipeRight];
}

- (IBAction)tappedRightButton:(id)sender
{
      NSUInteger selectedIndex = [self.tabBarController selectedIndex];

[self.tabBarController setSelectedIndex:selectedIndex + 1];
}

- (IBAction)tappedLeftButton:(id)sender
{
NSUInteger selectedIndex = [self.tabBarController selectedIndex];

[self.tabBarController setSelectedIndex:selectedIndex - 1];
}

这很简单,它应该进入每个视图控制器。