2016-12-12 27 views
0

我正在使用https://github.com/cwRichardKim/RKSwipeBetweenViewControllers在我的控制器之间滑动。 每一件事情都运行良好,我怎么想添加一个UIButton,我可以去其他视图控制器(不用刷卡)。 我从RKSwipeBetweenViewControllers导入了一个类,它们使用下面的代码创建一个uibutton如何从RKSwipeBetweenViewControllers(GitHub)调用选择器方法

UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(X_BUFFER+i*(self.view.frame.size.width-2*X_BUFFER)/numControllers-X_OFFSET, Y_BUFFER, (self.view.frame.size.width-2*X_BUFFER)/numControllers, HEIGHT)]; 

     [navigationView addSubview:button]; 

     [button addTarget:self action:@selector(tapSegmentButtonAction:) forControlEvents:UIControlEventTouchUpInside]; 

     [button setTitle:[buttonText objectAtIndex:i] forState:UIControlStateNormal]; 

和选择方法如下:

-(void)tapSegmentButtonAction:(UIButton *)button { 

    if (!self.isPageScrollingFlag) { 

     NSInteger tempIndex = self.currentPageIndex; 

     __weak typeof(self) weakSelf = self; 

     //%%% check to see if you're going left -> right or right -> left 
     if (button.tag > tempIndex) { 

      //%%% scroll through all the objects between the two points 
      for (int i = (int)tempIndex+1; i<=button.tag; i++) { 
       [pageController setViewControllers:@[[viewControllerArray objectAtIndex:i]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL complete){ 

        //%%% if the action finishes scrolling (i.e. the user doesn't stop it in the middle), 
        //then it updates the page that it's currently on 
        if (complete) { 
         [weakSelf updateCurrentPageIndex:i]; 
        } 
       }]; 
      } 
     } 

     //%%% this is the same thing but for going right -> left 
     else if (button.tag < tempIndex) { 
      for (int i = (int)tempIndex-1; i >= button.tag; i--) { 
       [pageController setViewControllers:@[[viewControllerArray objectAtIndex:i]] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:^(BOOL complete){ 
        if (complete) { 
         [weakSelf updateCurrentPageIndex:i]; 
        } 
       }]; 
      } 
     } 
    } 
} 

现在,当我从我的视图控制器调用此方法不会因为它在RKSwipeBetweenViewControllers做同一种方式响应。

下面是我用来调用这个选择器方法的代码。

[rkSwipeControllrObject tapSegmentButtonAction:myButtonObject]; 

回答

0

我希望你已经通过在RKSwipeBetweenViewControllers.h文件中声明这个方法来公开“tapSegmentButtonAction”方法。