在我的应用程序中。我想设计教程屏幕,我正在使用View Controller页面。我希望我的页面视图控制器自动滚动,页面控制也会更新。
帮助我。
-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{
NSUInteger index=((PageContantViewController *)viewController).pageIndex;
if(index==NSNotFound){
return nil;
}
index++;
if(index==[self.pageTitles count]){
return nil;
}
return [self viewControllerAtIndex:index];
}
-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController{
NSUInteger index= ((PageContantViewController *)viewController).pageIndex;
if(index==0 || index==NSNotFound){
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (PageContantViewController *)viewControllerAtIndex:(NSUInteger)index{
if([self.pageTitles count]==0 || index>=[self.pageTitles count]){
return nil;
}
PageContantViewController *contantVC=[self.storyboard instantiateViewControllerWithIdentifier:@"pageContantViewController"];
contantVC.titleText= _pageTitles[index];
contantVC.imageFile= _pageImages[index];
contantVC.pageIndex= index;
return contantVC;
}
-(NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController{
return [_pageTitles count];
}
-(NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController{
return 0;
}
答案 0 :(得分:3)
请使用此代码,它将为您提供帮助
- (void)viewDidLoad {
[super viewDidLoad];
currentIndex = 0;
self.delegate = self;
self.dataSource = self
// setup time interval here
[NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector:@selector(loadNextController)
userInfo:nil
repeats:YES];
// set main controller
NSArray *mainViewControllers = @[[self viewControllerAtIndex:self.index]];
[self setViewControllers: startingViewControllers
direction: UIPageViewControllerNavigationDirectionForward
animated: YES
completion: nil];
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return currentIndex;
}
- (void)loadNextController {
PageContentViewController *nextViewController = [self viewControllerAtIndex:currentIndex++];
if (nextViewController == nil) {
currentIndex = 0;
nextViewController = [self viewControllerAtIndex:currentIndex];
}
[self setViewControllers:@[nextViewController]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
}
答案 1 :(得分:-1)