【问题标题】:Why don't I see UIPageControl?为什么我看不到 UIPageControl?
【发布时间】:2014-12-22 16:03:39
【问题描述】:

我按照 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 单独的视图控制器的地方:

- (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。我的代码中缺少什么?

感谢您的任何建议。

【问题讨论】:

    标签: ios objective-c uipageviewcontroller uipagecontrol


    【解决方案1】:

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

    【讨论】:

    • 我按了 Control + Shift + K 一堆,就在我放弃时,它们出现了。不知道为什么这有效。在我寻找替代行动方案的过程中,可能做了 6 次。
    【解决方案2】:
    self.childPageControl = [[UIPageControl alloc] init];
    // self.childPageControl = [self getPageControlForPageViewController:self.pageController];
    self.childPageControl.alpha = .5;
    [self.view bringSubviewToFront:self.childPageControl];
    

    您绝不会将页面控件添加为子视图。 Xcode 中的视图调试器是发现此类缺失 UI 元素的好方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多