Note that there are some explanatory texts on larger screens.

plurals
  1. POArray value not retrieving outside method initWithViewControllers
    text
    copied!<p>I am using this method to move to next view controllers in page view controller as i am using two page mode. But the issue is that the array in not initialising that holds view controllers. I have spent a lots of hours in it already and don't know what is wrong. Code is below.</p> <p>Initialization method.</p> <pre><code>-(id)initWithViewControllers:(NSMutableArray *)Controllers { self = [super initWithNibName:nil bundle:nil]; if(self) { VControllers=[[NSMutableArray alloc]init]; VControllers = Controllers; pageController = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation: UIPageViewControllerNavigationOrientationHorizontal options:nil]; self.pageController.view.frame = CGRectMake(22.0f, 32.0f, 708.0f, 945.0f); self.pageController.delegate = self; self.pageController.dataSource = self; [self.pageController setViewControllers:[NSArray arrayWithObject:[VControllers objectAtIndex:0] ] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) { }]; [self addChildViewController:self.pageController]; [self.view addSubview:self.pageController.view]; [self.pageController didMoveToParentViewController:self]; } return self; } </code></pre> <p>button action</p> <pre><code>- (void)next1 { ViewThree *three = [[ViewThree alloc]init]; ViewFour *four = [[ViewFour alloc]init]; viewControllrs = [NSMutableArray arrayWithObjects:three,four, nil]; //[self initWithViewControllers:VControllers]; NSLog(@"viewControllrs :%@",viewControllrs); exampleViewController *currentViewController = [self.pageController.viewControllers objectAtIndex:0]; NSUInteger currentIndex = [self.viewControllrs indexOfObject:currentViewController]; if(currentIndex == 0 || currentIndex %2 == 0) { UIViewController *nextViewController = [self pageViewController:self.pageController viewControllerAfterViewController:currentViewController]; viewControllrs = [NSArray arrayWithObjects:currentViewController, nextViewController, nil]; } else { UIViewController *previousViewController = [self pageViewController:self.pageController viewControllerBeforeViewController:currentViewController]; viewControllrs = [NSArray arrayWithObjects:previousViewController, currentViewController, nil]; } //Now, set the viewControllers property of UIPageViewController [self.pageController setViewControllers:viewControllrs direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL]; } </code></pre> <p>This is the method to move to view controllers.</p> <pre><code>- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { int index ; index = [self.VControllers indexOfObject:viewController]; NSLog(@"index %d",index); NSLog(@"view cont %d",[self.VControllers count]); if (index + 1 &lt; [self.VControllers count]) { return [self.VControllers objectAtIndex:index + 1]; } return nil; } </code></pre> <p>First time it works fine. But when button acts, the array which was initialized in init method gets null. i tried to put that array values to another array in viewDidLoad, it gets also but when button method work, the array gets nil. Can anyone guide, what is going wrong here. Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload