gpt4 book ai didi

ios - 为什么我看不到 UIPageControl?

转载 作者:行者123 更新时间:2023-11-29 02:25:27 27 4
gpt4 key购买 nike

我按照 UIPageViewController 和 UIPageControl 上的 ios 文档遵循这些说明:

A page indicator will be visible if both methods are implemented, transition style is 'UIPageViewControllerTransitionStyleScroll', and navigation orientation is 'UIPageViewControllerNavigationOrientationHorizontal'. Both methods are called in response to a 'setViewControllers:...' call, but the presentation index is updated automatically in the case of gesture-driven navigation.

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController

所以我在 UIViewController 包装器类中按如下方式实现了它们:

这里是初始化:

@interface PageViewWrapperViewController : UIViewController <UIPageViewControllerDelegate, UIPageViewControllerDataSource>
@property (strong, nonatomic) UIPageViewController *pageController;
@property (assign, nonatomic) NSInteger index;
@property (strong, nonatomic) UILabel *screenNumber;
@property UIPageControl *childPageControl;
@end

- (void)viewDidLoad {
[super viewDidLoad];


self.index = 0;
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
self.pageController.delegate = self;
[self.pageController.view setFrame:[[self view] bounds]] ;
UIViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
//[self.pageController didMoveToParentViewController: self];

self.childPageControl = [[UIPageControl alloc] init];
// self.childPageControl = [self getPageControlForPageViewController:self.pageController];
self.childPageControl.alpha = .5;
[self.view bringSubviewToFront:self.childPageControl];


}

以下是 UIPageControl 所需的方法:

  - (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return 5;
}

-(NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return self.index;
}

这里是我给 PageController 单独的 View Controller 的地方:

- (UIViewController *)viewControllerAtIndex:(NSUInteger)index{

if(index==0)
{
//JudgeViewController *next1 = [[JudgeViewController alloc] init];
JudgeTutorViewController *next1 = [[JudgeTutorViewController alloc] init];
next1.view.userInteractionEnabled = NO;
return next1;

}
else if(index==1)
{
FollowTableViewController *next1 = [[FollowTableViewController alloc] init];
next1.view.userInteractionEnabled = NO;
next1.typeDisplay = 1;
return next1;

}
else if (index==2)
{
StatTutorViewController *next1 = [[StatTutorViewController
alloc] init];
next1.view.userInteractionEnabled = NO;
next1.user = [[UserObject userUnique] copyUser].name;
return next1;
}
else if (index==3)
{
MenuTutorViewController *next1 = [[MenuTutorViewController
alloc] init];
next1.view.userInteractionEnabled = NO;
return next1;
}
else if(index ==4)
{
BuzzTutorViewController *next1 = [[BuzzTutorViewController alloc] init];
next1.view.userInteractionEnabled = NO;
return next1;
}
self.index = index;
return nil;
}

UIPageViewController 本身工作正常,但我没有看到 UIPageControl。我的代码中缺少什么?

感谢您的任何建议。

最佳答案

实际上,这两个答案都不是问题所在。事实上,我并没有更改我的代码,但是一旦我刷新了几次我的build设置就成功了。谢谢大家!

关于ios - 为什么我看不到 UIPageControl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27606163/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com