RKSwipeBetweenViewControllers class below (Github library to swipe between controllers) it also provides an option where i can tap on buttons(which are names of viewControllers) how ever i am implementing a next button in each of my viewcontroller, so that if a user doesnot know he can swipe he can simply click on next button to go to next controller:
-(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];
}
and the selector method is below:
-(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];
}
}];
}
}
}
}
now i have created a global array of button created in above method and passed it in below code from another class.
Now i want to call the above method from first class using below code:
-(void)callMethodOfSecondClass {
UIButton *button = [globalArrayOfButtons objectAtIndex:1];
[rkSwipeControllrObject tapSegmentButtonAction:button];
}
Now the issue is obviously self.currentPageIndex is nil in second class.
How do i give it the value of its original earlier self.
Any help please