2016-10-24 69 views
0

我是新來使用UIPageViewController,IOS - UIPageViewController返回上一頁頁使用捲曲效果和顯示頁碼上的每個頁面

我想要的應用程序,刷卡左,右有同樣的觀點。我只使用一個uitableview來控制uipageviewcontroller的無限刷動。

Table View

這可是工作正常使用滾動效應在使用我頁捲曲效果,它只允許向右滑動並沒有去前一頁。

這裏是我的PageViewController文件的代碼:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.dataSource = self; 
    self.delegate = self; 
    [self didMoveToParentViewController:self]; 
    _counter = 0; 

    [self setViewControllers:@[[self.storyboard instantiateViewControllerWithIdentifier:@"memoTable"]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil]; 

    // Do any additional setup after loading the view. 
} 

- (BOOL)prefersStatusBarHidden { 
    return YES; 
} 

#pragma mark PageViewController delegate method 

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController 
{ 
    NSLog(@"Child controller counter before = %d", _counter); 

    if ([viewController isKindOfClass:[PageController class]]) 
     return nil; 

    if(_counter < 1) { 
     return nil; 
    } 

    self.view.backgroundColor = [UIColor lightGrayColor]; 
    return [self.storyboard instantiateViewControllerWithIdentifier:@"memoTable"]; 
} 

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController 
{ 
    NSLog(@"Child controller counter after = %d", _counter); 
    if ([viewController isKindOfClass:[PageController class]]) 
     return nil; 
    return [self.storyboard instantiateViewControllerWithIdentifier:@"pageView"]; 
} 

那麼,如何才能做到這一點使用頁面捲曲效果和刷卡左右。

謝謝。

+0

你有沒有嘗試第一頁捲曲的權利和比左?你能夠得到左刷卡委託? – CodeChanger

+0

如果我刪除返回零;在櫃檯<1比我得到它無限的雙方工作。但是我只想在頁面捲曲中右側無限。 @Dhanesh – KAR

回答

0

由於您需要的是在單邊無限您需要檢查您index,如果它的0比return nil

檢查PageViewController一些方法:

// Create the data model. 
     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
     _pageData = [[dateFormatter monthSymbols] copy]; 

- (DataViewController *)viewControllerAtIndex:(NSUInteger)index storyboard:(UIStoryboard *)storyboard { 
    // Return the data view controller for the given index. 
    if (([self.pageData count] == 0) || (index >= [self.pageData count])) { 
     return nil; 
    } 

    // Create a new view controller and pass suitable data. 
    DataViewController *dataViewController = [storyboard instantiateViewControllerWithIdentifier:@"DataViewController"]; 
    dataViewController.dataObject = self.pageData[index]; 
    return dataViewController; 
} 

- (NSUInteger)indexOfViewController:(DataViewController *)viewController { 
    // Return the index of the given data view controller. 
    // For simplicity, this implementation uses a static array of model objects and the view controller stores the model object; you can therefore use the model object to identify the index. 
    return [self.pageData indexOfObject:viewController.dataObject]; 
} 

#pragma mark - Page View Controller Data Source 

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController 
{ 
    NSUInteger index = [self indexOfViewController:(DataViewController *)viewController]; 
    if ((index == 0) || (index == NSNotFound)) { 
     return nil; 
    } 

    index--; 
    return [self viewControllerAtIndex:index storyboard:viewController.storyboard]; 
} 

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController 
{ 
    NSUInteger index = [self indexOfViewController:(DataViewController *)viewController]; 
    if (index == NSNotFound) { 
     return nil; 
    } 

    index++; 
    if (index == [self.pageData count]) { 
     return nil; 
    } 
    return [self viewControllerAtIndex:index storyboard:viewController.storyboard]; 
} 

你必須還管理一個陣列識別每一件事index | count

在上述情況下self.pageData是我的數組來管理頁面。 如果您需要任何幫助,請讓我知道。

+0

你可以添加你的數組和什麼是DataViewController? @CodeChanger – KAR

+0

'DataViewController'只是viewcontroller,我需要在頁面視圖中顯示。 – CodeChanger

+0

你的數組中有什麼樣的數據?我怎樣才能使用這個數組? @CodeChanger – KAR