【发布时间】:2017-04-30 16:43:15
【问题描述】:
RKSwipeBetweenViewControllers 下面的类(Github 库在控制器之间滑动)它还提供了一个选项,我可以在其中点击按钮(它们是 viewControllers 的名称)我如何在每个 viewcontroller 中实现下一个按钮,这样如果用户不知道他可以滑动,他只需点击下一步按钮即可转到下一个控制器:
-(void)setupSegmentButtons {
navigationView = [[UIView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.navigationBar.frame.size.height)];
NSInteger numControllers = [viewControllerArray count];
if (!buttonText) {
buttonText = [[NSArray alloc]initWithObjects: @"Login",@"Personal",@"Contact",@"Club Info",nil]; //%%%buttontitle
}
for (int i = 0; i<numControllers; i++) {
RKButton = [[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:RKButton];
RKButton.tag = i; //%%% IMPORTANT: if you make your own custom buttons, you have to tag them appropriately
[RKButton setBackgroundColor:ThemeColor];//%%% buttoncolors
[RKButton addTarget:self action:@selector(tapSegmentButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//[RKButton addTarget:self action:@selector(CalltapSegmentButtonAction) forControlEvents:UIControlEventTouchUpInside];
[RKButton setTitle:[buttonText objectAtIndex:i] forState:UIControlStateNormal]; //%%%buttontitle
[_RKSwipeRegisterModal.RKButtonArray addObject:RKButton];
NSLog(@"_RKSwipeRegisterModal.RKButtonArray %@",_RKSwipeRegisterModal.RKButtonArray);
}
pageController.navigationController.navigationBar.topItem.titleView = navigationView;
[self setupSelector];
}
选择器方法如下:
-(void)tapSegmentButtonAction:(UIButton *)RKButton {
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 (RKButton.tag > tempIndex) {
//%%% scroll through all the objects between the two points
for (int i = (int)tempIndex+1; i<=RKButton.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 (RKButton.tag < tempIndex) {
__weak typeof(self) kjhg = self;
for (int i = (int)tempIndex-1; i >= RKButton.tag; i--) {
[pageController setViewControllers:@[[viewControllerArray objectAtIndex:i]] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:^(BOOL complete){
if (complete) {
[weakSelf updateCurrentPageIndex:i];
}
}];
}
}
}
}
现在我已经创建了一个在上述方法中创建的全局按钮数组,并将其从另一个类传递到下面的代码中。
现在我想使用下面的代码从头等舱调用上述方法:
-(void)callMethodOfSecondClass {
UIButton *button = [globalArrayOfButtons objectAtIndex:1];
[rkSwipeControllrObject tapSegmentButtonAction:button];
}
现在问题显然是 self.currentPageIndex 在第二类中为零。
我如何赋予它原来的早期自我的价值。
请帮忙
【问题讨论】:
-
您是在展示或推送第二个视图控制器吗?
-
第二类都不是,其实是第三方类库,但我想调用第二类的方法。
-
@ios_Dev。您的问题无法完全理解。请添加更多内容以了解我们,然后我们可以为您提供帮助