Mengapa saya tidak melihat UIPageControl?

Saya mengikuti petunjuk ini sesuai dokumen ios di UIPageViewController dan 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 

Jadi saya telah menerapkannya sebagai berikut, di dalam kelas pembungkus UIViewController:

Berikut inisialisasinya:

@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];


    }

Berikut adalah metode yang diperlukan untuk UIPageControl:

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

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

Dan di sinilah saya memberikan PageController pengontrol tampilan individual:

- (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 sendiri berfungsi dengan baik, tetapi saya tidak melihat UIPageControl. Apa yang hilang dari kode saya?

Terima kasih atas sarannya.


person Sunnyside Productions    schedule 22.12.2014    source sumber


Jawaban (2)


Sebenarnya, tidak satu pun dari jawaban ini yang menjadi masalahnya. Faktanya, saya tidak mengubah kode saya tetapi setelah saya menghapus pengaturan build saya beberapa kali, itu berhasil. Terima kasih semua!

person Sunnyside Productions    schedule 22.12.2014
comment
Saya menekan Control + Shift + K berkali-kali dan saat saya menyerah, mereka muncul. Tidak yakin mengapa ini berhasil. Mungkin melakukannya 6 kali ketika saya sedang mencari tindakan alternatif. - 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];

Anda tidak boleh menambahkan kontrol halaman sebagai subview. Debugger tampilan di Xcode adalah cara terbaik untuk menemukan elemen UI yang hilang seperti ini.

person jrturton    schedule 22.12.2014