2016-12-12 5 views
0

Я использую https://github.com/cwRichardKim/RKSwipeBetweenViewControllers для прокрутки между моими контроллерами. Все отлично работает, как бы то ни было, я хочу добавить UIButton, на котором я могу перейти на другой контроллер представления (без использования swiping.) Я импортировал класс из 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

Я надеюсь, что вы сделали «tapSegmentButtonAction» метод общественного объявляя это в файле RKSwipeBetweenViewControllers.h.