UIPageviewcontroller在前两次滑动视图时无法工作

时间:2014-03-20 10:32:13

标签: ios objective-c ios7 uipageviewcontroller

Pageviewcontroller工作后前两次滑动不工作。我不知道我的代码中有什么问题。请参考下面的代码

PageViewController编码

- (void)viewDidLoad
{
[super viewDidLoad];

self.sampleImage=@[@"sample1.jpeg",@"sample2.jpeg",@"sample3.jpeg"];
self.sampleContent=@[@"sample1",@"sample2",@"sample3"];

self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.dataSource = self;


MYViewCtrl *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = @[startingViewController];

self.pagecontrol= [UIPageControl appearanceWhenContainedIn:[self.pageViewController class], nil];
self.pagecontrol.currentPageIndicatorTintColor = [UIColor colorWithRed:152.0/225.0 green:10.0/225.0 blue:115.0/225.0 alpha:1.0];
self.pagecontrol.pageIndicatorTintColor = [UIColor colorWithRed:121.0/255.0 green:121.0/255.0 blue:121.0/255.0 alpha:1.0];


self.pageViewController.view.frame = CGRectMake(0, 0, self.myview.frame.size.width, self.myview.frame.size.height+35);
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

[self addChildViewController:_pageViewController];
[self.myview addSubview:_pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];


}
- (MYViewCtrl *)viewControllerAtIndex:(NSUInteger)index
{
if (([self.sampleImage count] == 0) || (index >= [self.sampleImage count])) {
return nil;
}


MYViewCtrl *childViewController = [[MYViewCtrl alloc] initWithNibName:@"MYViewCtrl" bundle:nil];
childViewController.Image = self.sampleImage[index];
childViewController.Content = self.sampleContent[index];
childViewController.pageIndex=index;
return childViewController;

}-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController          viewControllerBeforeViewController:(UIViewController *)viewController{
NSUInteger index = ((MYViewCtrl*) viewController).pageIndex;

if ((index == 0) || (index == NSNotFound)) {
    return nil;
}

index--;
return [self viewControllerAtIndex:index];
}-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{
NSUInteger index = ((MYViewCtrl*) viewController).pageIndex;

if (index == NSNotFound) {
    return nil;
}

index++;
if (index == [self.sampleImage count]) {
    return nil;
}
return [self viewControllerAtIndex:index];
}
-(NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController{
 return [self.sampleImage count];
}
-(NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}

任何人都可以帮我解决这个问题。

0 个答案:

没有答案