เหตุใดฉันจึงไม่เห็น UIPageControl

ฉันทำตามคำแนะนำเหล่านี้ตามเอกสาร iOS บน UIPageViewController และ UIPageControl:

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 

ดังนั้นฉันจึงได้นำไปใช้ดังต่อไปนี้ภายในคลาส wrapper 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 รหัสของฉันหายไปอะไร?

ขอบคุณสำหรับข้อเสนอแนะใด ๆ


person Sunnyside Productions    schedule 22.12.2014    source แหล่งที่มา


คำตอบ (2)


จริงๆ แล้ว คำตอบเหล่านี้ไม่ใช่ว่าปัญหาคืออะไร จริงๆ แล้ว ฉันไม่ได้เปลี่ยนโค้ด แต่เมื่อล้างการตั้งค่าบิลด์สองสามครั้งก็ได้ผล ขอบคุณทุกคน!

person Sunnyside Productions    schedule 22.12.2014
comment
ฉันกด Control + Shift + K เป็นกลุ่มๆ และเมื่อฉันยอมแพ้ พวกมันก็ปรากฏตัวขึ้น ไม่แน่ใจว่าทำไมสิ่งนี้ถึงได้ผล อาจจะทำ 6 ครั้งในขณะที่ฉันกำลังมองหาแนวทางปฏิบัติอื่น - person agrippa; 06.09.2017

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

คุณกำลังเพิ่มการควบคุมหน้าเป็นมุมมองย่อยไม่ว่าในเวลาใดก็ตาม view debugger ใน Xcode เป็นวิธีที่ดีในการระบุองค์ประกอบ UI ที่ขาดหายไปเช่นนี้

person jrturton    schedule 22.12.2014