首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >目标-C开关标签使用滑动

问目标-C开关标签使用滑动
EN

Stack Overflow用户
提问于 2015-11-04 05:52:08
回答 1查看 691关注 0票数 2

我遵循一个代码,当用户在屏幕上左右滑动时切换选项卡。问题是,当我切换到其他选项卡时,选项卡栏就消失了。

我试着推一个navigationController,但是它抛出了一个错误,表示它不受支持。

以下是代码:

代码语言:javascript
复制
- (void)viewDidLoad {
    [super viewDidLoad];
    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
    swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:swipeLeft];
    swipeLeft.delegate = self;

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

-(void) swipeRight:(UISwipeGestureRecognizer *) recognizer {
    if (recognizer.direction == UISwipeGestureRecognizerDirectionRight){
        //NSLog(@"swipe right");
        NSString * storyboardName = @"Main";
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
        UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"RecentsController"];
        [self presentViewController:vc animated:YES completion:nil];

    }
}

-(void) swipeLeft:(UISwipeGestureRecognizer *) recognizer {
    if (recognizer.direction == UISwipeGestureRecognizerDirectionRight)
        NSLog(@"Swipe left");
    NSString * storyboardName = @"Main";
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
    UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"SettingsController"];
    [self presentModalViewController:vc animated:YES];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-04 06:13:14

你这样做是不对的。要通过code切换Tab,您不必推一个新的ViewController,它将取代现有的ViewController。

要做到这一点,您可以使用以下方法之一:

代码语言:javascript
复制
self.tabBarController.selectedIndex = i;

或

代码语言:javascript
复制
[self.tabBarController setSelectedIndex:i];

* i是您想要显示的ViewController的index。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33514625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档