ios – 在UIPageViewController中,何时调用“pageViewController:viewControllerBeforeViewController”?

ios – 在UIPageViewController中,何时调用“pageViewController:viewControllerBeforeViewController”?,第1张

概述我尝试在UIPageViewController中显示照片.首先,我在集合视图中显示我的照片,然后点击一张照片进入页面视图.然而,当我在页面视图中时,如果我滚动当前照片(向右或向左),我发现将调用pageViewController:viewControllerBeforeViewController和pageViewController:viewControllerAfterViewContro 我尝试在UIPageVIEwController中显示照片.首先,我在集合视图中显示我的照片,然后点击一张照片进入页面视图.然而,当我在页面视图中时,如果我滚动当前照片(向右或向左),我发现将调用pageVIEwController:vIEwControllerBeforeVIEwController和pageVIEwController:vIEwControllerAfterVIEwController方法(通过调用NSLog我发现它).

应该只调用两种方法中的一种吗?我对此非常困惑,并且更新我的photoNumber以显示我想要的照片时遇到大麻烦.

这是我的页面查看代码:

#import "PhotopageVIEwController.h"#import "PhotoVIEwController.h"@interface PhotopageVIEwController ()@property (nonatomic)NSInteger prevIoUsPhotoNumber;@end@implementation PhotopageVIEwController- (voID)vIEwDIDLoad{    [super vIEwDIDLoad];    self.dataSource = self;    self.delegate = self;    self.numberOfPhotosInCurrentAlbum = [Photo numberOfPhotosInAlbumWithname:self.albumname inManagedobjectContext:self.context];    PhotoVIEwController *currentPhotoVIEwController = [self.storyboard instantiateVIEwControllerWithIDentifIEr:@"PhotoContentVIEwController"];    currentPhotoVIEwController.photoNumber = self.currentPhotoNumber;    currentPhotoVIEwController.albumname = self.albumname;    currentPhotoVIEwController.context = self.context;    currentPhotoVIEwController.ppvc = self;    currentPhotoVIEwController.numberOfPhotosInCurrentAlbum =self.numberOfPhotosInCurrentAlbum;    [self setVIEwControllers:@[currentPhotoVIEwController]                   direction:UIPageVIEwControllerNavigationDirectionForward                    animated:NO                  completion:NulL];}#pragma mark - Page VIEw Controller Datasource- (UIVIEwController *)pageVIEwController:(UIPageVIEwController *)pageVIEwController vIEwControllerBeforeVIEwController:(UIVIEwController *)vIEwController{    if (self.currentPhotoNumber > 0) {        NSLog(@"in before section: current photo %lu",self.currentPhotoNumber);        PhotoVIEwController *photoBeforeCurrentPhoto = [self.storyboard instantiateVIEwControllerWithIDentifIEr:@"PhotoContentVIEwController"];        photoBeforeCurrentPhoto.photoNumber = self.currentPhotoNumber - 1;        photoBeforeCurrentPhoto.albumname = self.albumname;        photoBeforeCurrentPhoto.context = self.context;        photoBeforeCurrentPhoto.ppvc = self;        self.prevIoUsPhotoNumber = self.currentPhotoNumber;        self.currentPhotoNumber--;        return photoBeforeCurrentPhoto;    }    return nil;}- (UIVIEwController *)pageVIEwController:(UIPageVIEwController *)pageVIEwController vIEwControllerAfterVIEwController:(UIVIEwController *)vIEwController{    if (self.currentPhotoNumber < self.numberOfPhotosInCurrentAlbum - 1) {        NSLog(@"in after section: current photo %lu",self.currentPhotoNumber);        PhotoVIEwController *photoAfterCurrentPhoto = [self.storyboard instantiateVIEwControllerWithIDentifIEr:@"PhotoContentVIEwController"];        photoAfterCurrentPhoto.photoNumber = self.currentPhotoNumber + 1;        photoAfterCurrentPhoto.albumname = self.albumname;        photoAfterCurrentPhoto.context = self.context;        photoAfterCurrentPhoto.ppvc = self;        self.prevIoUsPhotoNumber = self.currentPhotoNumber;        self.currentPhotoNumber++;        return photoAfterCurrentPhoto;    }    return nil;}

PhotoVIEwController是显示照片的视图控制器.

任何人都可以给我一些关于UIPageVIEwController使用的建议吗?

提前致谢!

解决方法 UIPageVIEwController使用这些波纹管方法来获取后面和前面的VIEwController.

- (UIVIEwController *)pageVIEwController:(UIPageVIEwController *)pageVIEwController vIEwControllerBeforeVIEwController:(UIVIEwController *)vIEwController;- (UIVIEwController *)pageVIEwController:(UIPageVIEwController *)pageVIEwController vIEwControllerAfterVIEwController:(UIVIEwController *)vIEwController;

虽然它很奇怪但是它是一个已知的问题.每次调用Before和After方法获取VC.它没有下一个VC然后返回nil,如果没有以前的VC,则datasourceDelegate返回nil,否则返回VC的索引.

在UIPageVIEwControllerDelegate中,有一个名为的函数:

- (voID)pageVIEwController:(UIPageVIEwController *)pageVIEwController willTransitionToVIEwControllers:(NSArray *)pendingVIEwControllers;

看看这可能有助于从pendingVIEwControllers数组中获取当前或下一个/上一个vIEwcontroller.

希望这可以帮助.. :)

@H_404_50@ 总结

以上是内存溢出为你收集整理的ios – 在UIPageViewController中,何时调用“pageViewController:viewControllerBeforeViewController”?全部内容,希望文章能够帮你解决ios – 在UIPageViewController中,何时调用“pageViewController:viewControllerBeforeViewController”?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1023320.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存