2015-07-02 38 views

回答

1

在管理你的UIPageViewController類:

有像

@property NSInteger currentIndex; 

實例化一個屬性爲0,並且每次要切換到另一個viewController,更新其值(_currentIndex ++/_currentIndex--)

然後實例化一個的NSTimer:

[NSTimer scheduledTimerWithTimeInterval:10.0 
    target:self 
    selector:@selector(changeController:) 
    userInfo:nil 
    repeats:YES]; 

並添加此方法

- (void) changeController:(NSTimer*)timer 
{ 
    UIViewController yourViewController = [self itemControllerForIndex: self.currentIndex+1]; 
    self.currentIndex++; 
    NSArray *array = [NSArray arrayWithObjects:yourViewController] 
    [yourPageViewController setViewControllers:array direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; 
} 

希望它可以幫助...

+0

非常感謝你:) – miljan

0

您每次需要更改頁面時都需要調用- setViewControllers:direction:animated:completion:方法。

您可以使用NSTimer來激發您自己的中間方法,該方法使用上述方法設置相應的頁面。

+0

好的,這裏是我的代碼,PLZ幫助我::D – miljan

0

這裏是我的代碼:

- (UIViewController *) pageViewController: (UIPageViewController *) pageViewController viewControllerBeforeViewController:(UIViewController *) viewController 
    { 
     HelpPageViewController *itemController = (HelpPageViewController *) viewController; 

     if (itemController.itemIndex > 0) 
     { 
      return [self itemControllerForIndex: itemController.itemIndex-1]; // bilo je -1 
     } 



     return nil; 

     } 

    - (UIViewController *) pageViewController: (UIPageViewController *) pageViewController viewControllerAfterViewController:(UIViewController *) viewController 
    { 
     HelpPageViewController *itemController = (HelpPageViewController *) viewController; 

     if (itemController.itemIndex+1 < [contentImages count]) // bilo je < 
     { 
      return [self itemControllerForIndex: itemController.itemIndex+1]; 
     } 

     return nil; 


    } 

    UIPageViewController *scrollingHeader = [self.storyboard instantiateViewControllerWithIdentifier: @"ScrollingHeader"]; 
     scrollingHeader.dataSource = self; 

     if([contentImages count]) 
     { 


      NSArray *startingViewControllers = @[[self itemControllerForIndex: 0]]; 
      [scrollingHeader setViewControllers: startingViewControllers 
            direction: UIPageViewControllerNavigationDirectionForward 

             animated: NO 
            completion: nil]; 
     } 

     self.pageViewController = scrollingHeader; 
     [self addChildViewController: self.pageViewController]; 
     [self.view addSubview: self.pageViewController.view]; 



     [self.pageViewController didMoveToParentViewController: self];