如何在使用按钮时弹回以及在viewController上滑动手势

时间:2013-01-18 12:02:40

标签: iphone ios objective-c ipad

我这里有2个场景。 1.点击VC1按钮,我想移动到VC6,然后向后滑动。这是通过上述代码完成的。 2.我还在VC1中滑动手势以移动到VC2,Vc3,VC4,VC5和VC6。现在我想从VC6刷回VC5,Vc4,VC3,VC2然后再转移到VC1。我可以分别实现这两个场景。但是我怎样才能一起实现这些场景。

我有六个viewControllers。在viewController1我有一个按钮,可以将我带到viewController6。然后我使用代码

分别从viewController5回到viewController4viewController3viewController2viewController1viewController6
    - (IBAction)SwipeGoto5:(UISwipeGestureRecognizer *)sender 
{
    IndexPage *P1VC=[[IndexPage alloc] initWithNibName:@"IndexPage" bundle:nil];
    Page2 *P2VC=[[Page2 alloc] initWithNibName:@"Page2" bundle:nil];
    Page3 *P3VC=[[Page3 alloc] initWithNibName:@"Page3" bundle:nil];
    Page4 *P4VC=[[Page4 alloc] initWithNibName:@"Page4" bundle:nil];
    Page5 *P5VC=[[Page5 alloc] initWithNibName:@"Page5" bundle:nil];

    NSLog(@"swipe to 5");
    NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray: self.navigationController.viewControllers];
    [allViewControllers insertObject:P1VC atIndex:1];
    [allViewControllers insertObject:P2VC atIndex:2];
    [allViewControllers insertObject:P3VC atIndex:3];
    [allViewControllers insertObject:P4VC atIndex:4];
    [allViewControllers insertObject:P5VC atIndex:5];

    self.navigationController.viewControllers=allViewControllers;
    [self.navigationController popViewControllerAnimated:YES];


}

UISwipeGestureRecognizer上还有viewController1,它带我到viewController2viewController3viewController4以及viewController6。当我在viewController6上使用UISwipeGestureRecognizer并且我也有上述代码时,我将如何从viewController1回弹。

1 个答案:

答案 0 :(得分:0)

获取滑动手势(从右到左)并在其中编写popViewController的代码。