- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道这可能是重复的,但我尝试了在网上找到的其他解决方案,但似乎都没有解决我的问题。
我有一个 pageViewController,它显示 4 个 UIViewController。首先滚动 pageController 滑动到第三个 View Controller ,但显示第二个 ViewController。
这是我的代码:
_contentPageRestorationIDs = [[NSArray alloc]initWithObjects:@"PRPeripheralsOriantaionVC",@"PRSessionAnalysisDataVC", @"PRNavigationVC",@"PRVideoVC", nil];
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return self.contentPageRestorationIDs.count;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSString *vcRestorationID = viewController.restorationIdentifier;
NSUInteger index = [self.contentPageRestorationIDs indexOfObject:vcRestorationID];
NSLog(@"viewControllerBeforeViewController %@",vcRestorationID);
if (index == 0)
{
return nil;
}
index--;
return [self viewControllerAtIndex:index ];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSString *vcRestorationID = viewController.restorationIdentifier;
NSLog(@"viewControllerAfterViewController %@",vcRestorationID);
NSUInteger index = [self.contentPageRestorationIDs indexOfObject:vcRestorationID];
index ++;
if (index == self.contentPageRestorationIDs.count )
{
return nil;
}
return [self viewControllerAtIndex:index ];
}
- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers
{
NSLog(@"willTransitionToViewControllers %@ %lu",pendingViewControllers,(unsigned long)index);
}
-(void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{
NSLog(@"didFinishAnimating %@",previousViewControllers);
}
最佳答案
你有一个错误,更新你的数据源方法:
h 文件
@interface ViewController : UIPageViewController
@end
文件
#import "ViewController.h"
@interface ViewController ()<UIPageViewControllerDataSource>
@property (strong, nonatomic) NSArray *pageColors;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.pageColors = @[@"green", @"yellow", @"black", @"red"];
self.dataSource = self;
UIViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = @[startingViewController];
[self setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Private method
- (UIViewController *)viewControllerAtIndex:(NSUInteger)index
{
if (([self.pageColors count] == 0) || (index >= [self.pageColors count])) {
return nil;
}
NSString* pageColor = self.pageColors[index];
// Create a new view controller and pass suitable data.
UIViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:pageColor];
return pageContentViewController;
}
#pragma mark - Page View Controller Data Source
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController
{
NSString * identifier = viewController.restorationIdentifier;
NSUInteger index = [self.pageColors indexOfObject:identifier];
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController
{
NSString * identifier = viewController.restorationIdentifier;
NSUInteger index = [self.pageColors indexOfObject:identifier];
if (index == NSNotFound) {
return nil;
}
index++;
if (index == [self.pageColors count]) {
return nil;
}
return [self viewControllerAtIndex:index];
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return [self.pageColors count];
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
@end
不要忘记为每个 View Controller 更改 Storyboard ID 及其颜色([@"green", @"yellow", @"black", @"red"])。例如,对于读取 View Controller :
关于ios - UIPageViewControllerDataSource 第一次运行时调用 viewControllerAfterViewController 两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30284975/
我有一个 UIPageViewController,我设置了一个数组作为数据源。我看到第一页很好,演示文稿计数点显示正确,但是当我尝试将 拖到下一页时,没有任何反应。因此,我在 viewControl
我设置了 UIPageViewController 的 dataSource 属性,但它的函数从未被调用,并且 View 是空的(黑色)。 如果我使用以下方法至少设置了第一页,一切正常,并且调用了数据
我知道这可能是重复的,但我尝试了在网上找到的其他解决方案,但似乎都没有解决我的问题。 我有一个 pageViewController,它显示 4 个 UIViewController。首先滚动 pag
我遇到了 UIPageViewController 的一个非常奇怪的行为。 我正在使用 UIPageViewController 显示一组 ViewController,因此我遵循 UIPageVie
我正在尝试实现 UIPageViewController 并在每一步都进行验证。我的代码在没有验证的情况下工作正常,所以页面上的所有内容似乎都是正确的。这是我的代码: - (UIViewControl
我是一名优秀的程序员,十分优秀!