【问题标题】:How to call selector method from RKSwipeBetweenViewControllers(GitHub)如何从 RKSwipeBetweenViewControllers(GitHub) 调用选择器方法
【发布时间】:2016-12-12 08:23:45
【问题描述】:

我正在使用https://github.com/cwRichardKim/RKSwipeBetweenViewControllers 在我的控制器之间滑动。 每件事都运行良好,我想添加一个 UIButton,我可以在其上转到另一个视图控制器(无需滑动。) 我已经从 RKSwipeBetweenViewControllers 导入了一个类,他们在其中使用下面的代码来创建一个 uibutton

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

【问题讨论】:

    标签: ios objective-c methods xcode7 call


    【解决方案1】:

    我希望您通过在 RKSwipeBetweenViewControllers.h 文件中声明它来公开“tapSegmentButtonAction”方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多