1
Answer

How to create a page slider having 3 view controllers in it.

I need help with ios proramming using objective C.
 
 
I m creating page slider using page view controller but when i click on second VC when the program is running it crashes after the second VC so i dont know how to manage that .
I want 3 view controllers under that page view controller or if it doesnt crash then i get repetitive view controllers in it ,this is my second view controller code
 
 

- (void)viewDidLoad

{

PagedImageScrollView *pageScrollView = [[PagedImageScrollView alloc] initWithFrame:CGRectMake(0, 32, 320, 165)];

[pageScrollView setScrollViewContents:@[[UIImage imageNamed:@"slider1"], [UIImage imageNamed:@"slider2"],[UIImage imageNamed:@"slider3"]]];

pageScrollView.pageControlPos = PageControlPositionCenterBottom;

[self.view addSubview:pageScrollView];

pageScrollView.delegate1 = self;

self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"];

self.pageViewController.dataSource = self;


PageContentViewController *startingViewController = [self secondviewcontrollerAtIndex:0];

//secondviewcontroller *startingViewController = [self secondviewcontrollerAtIndex:0];

//

NSArray *viewControllers = @[startingViewController];

[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

// PageContentViewController2 *startingViewController2 = [self secondviewcontrollerAtIndex:0];

//

// NSArray *viewControllers2 = @[startingViewController2];

//

//

// [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

// [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

//

// Change the size of page view controller

self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height + 40);

[self addChildViewController:_pageViewController];

[self.view addSubview:_pageViewController.view];

[self.pageViewController didMoveToParentViewController:self];


}

- (IBAction)buttonLeague:(id)sender {

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

LeaguesViewController* Leagues = [storyboard instantiateViewControllerWithIdentifier:@"Leagues"];

// Leagues.imageFile = @"slider1";

[self presentViewController:Leagues animated:YES completion:nil];

}


- (IBAction)sportsBtn:(id)sender {

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

LeaguesViewController* Leagues = [storyboard instantiateViewControllerWithIdentifier:@"Leagues"];

// Leagues.imageFile = @"slider1";

Leagues.navTitle = @"sports";

Leagues.pageName = @"second";

[self presentViewController:Leagues animated:YES completion:nil];

}



- (IBAction)Event:(id)sender {

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

LeaguesViewController* Leagues = [storyboard instantiateViewControllerWithIdentifier:@"Leagues"];

// Leagues.imageFile = @"slider1";

Leagues.navTitle = @"event";

Leagues.pageName = @"second";

[self presentViewController:Leagues animated:YES completion:nil];

}


- (IBAction)Location:(id)sender {

}


- (IBAction)MenuClicked:(id)sender {

[self.view endEditing:YES];

[self.frostedViewController.view endEditing:YES];

// Present the view controller

//

[self.frostedViewController presentMenuViewController];

}


- (IBAction)Tournament:(id)sender {

}




-(void)buttonWasPressed

{


NSLog(@"First image tapped");

}




- (IBAction)startWalkthrough:(id)sender {

}





- (PageContentViewController *)secondviewcontrollerAtIndex:(NSUInteger)index

{

// if (([self.pageTitles count] == 0) || (index >= [self.pageTitles count])) {

PageContentViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageContentViewController"];

// pageContentViewController.imageFile = self.pageImages[index];

// pageContentViewController.titleText = self.pageTitles[index];

pageContentViewController.pageIndex = index;

return pageContentViewController;

}


#pragma mark - Page View Controller Data Source


- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)secondviewcontroller

{

NSUInteger index = ((PageContentViewController*) secondviewcontroller).pageIndex;

if ((index == 0) || (index == NSNotFound)) {

return nil;

}

index++;

return [self secondviewcontrollerAtIndex:index];

}


- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)PageContentViewController

{

NSUInteger index = ((PageContentViewController2*) PageContentViewController).pageIndex;

if (index == NSNotFound) {

return nil;

}

index--;

// if (index == [self.pageTitles count]) {

// return nil;

// }

return [self secondviewcontrollerAtIndex:index];

}


- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController

{

// return [self.pageTitles count];

return 2;

}


- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController

{

return 0;

}



@end



Answers (1)