2016-12-12 6 views
0

https://github.com/cwRichardKim/RKSwipeBetweenViewControllersを使用して、コントローラ間をスワイプします。 すべてのことがうまく動作します。UIButtonを追加したいときは、別のビューコントローラに移動することができます(スワイプなしで)。 RKSwipeBetweenViewControllerからクラスをインポートしました。下のコードを使用して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]; 

とセレクタ方法は以下の通りです:私は私のビューコントローラからこのメソッドを呼び出したとき、それはRKSwipeBetweenViewControllersの場合と同様

-(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]; 
        } 
       }]; 
      } 
     } 
    } 
} 

は、今では同じように応答しません。

以下は、このセレクタメソッドを呼び出すために使用しているコードです。

[rkSwipeControllrObject tapSegmentButtonAction:myButtonObject]; 

答えて

0

RKSwipeBetweenViewControllers.hファイルでこれを宣言することで、「tapSegmentButtonAction」メソッドを公開したことを期待します。

関連する問題