3

I have been working on implementing UIPageViewController for some time now. I have went through many problems that i managed to solve by myself and with some extra help. Now i am stuck with the last part and that is the UIPageControl.

I got two problems that i would like some help with:

Problem 1: Is there any simple way to resize the dots for the pageControl?

Problem 2: This is how it is built:

enter image description here

I know it is hard to see but i will explain them starting from the upper left corner and going to right. First VC is simply a Navigation Controller pointing to a UITableViewController.

in the second row the first VC is the datasource delegate for the UIPageVIewController. The one next to it is the PageViewController, The two UITableView's next to it is the "pages" that are in the UIPageViewController. And the last one is the PageContentViewController.

So i added this code in viewDidLoad to the datasource VC meaning the first VC in the second row:

self.navigationController.delegate = self;
CGSize navBarSize = self.navigationController.navigationBar.bounds.size;
CGPoint origin = CGPointMake( navBarSize.width/2, navBarSize.height/2 );
self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(origin.x, origin.y+16,
                                                                   0, 0)]; //Here added 45 to Y and it did the trick



self.pageControl.pageIndicatorTintColor = navbarColor;
self.pageControl.currentPageIndicatorTintColor = [UIColor lightGrayColor];

[self.pageControl setNumberOfPages:2];

and

- (void)navigationController:(UINavigationController *)navigationController     willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    int index = [self.navigationController.viewControllers indexOfObject:viewController];
    self.pageControl.currentPage = index;  }

Which gives me this result:

enter image description here

Which is perfect, I can swipe right and left and the PageControl shows the right indicator etc. However when i leave the "UIPageViewController" meaning when i click back. The PageController still appears in the first VC in the first picture. Why does it tag along and not get removed and how can i solve this?

If you need extra codes / pictures that would make it easier to understand just tell me. Thank you!

EDIT

Okay so i solved the first problem thanks to the comment of removing it in viewWillDissapear. I used this code in the datasource ViewController:

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:YES];

    [self.pageControl removeFromSuperview];

}

The PageControl now only shows where it should be BUT there is one problem that i forgot to mention. After clicking the back button the pageControl is no gone which is great. However when i switch to another UITabBarItem and then back again then the app crashes. This happened before and after the fix. Here is how it looks:

enter image description here

Removing the code that i used to implement the PageController fixes the problem:

self.navigationController.delegate = self;
CGSize navBarSize = self.navigationController.navigationBar.bounds.size;
CGPoint origin = CGPointMake( navBarSize.width/2, navBarSize.height/2 );
self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(origin.x, origin.y+16,
                                                                   0, 0)]; //Here added 45 to Y and it did the trick



self.pageControl.pageIndicatorTintColor = navbarColor;
self.pageControl.currentPageIndicatorTintColor = [UIColor lightGrayColor];

[self.pageControl setNumberOfPages:2];
hamzah
  • 375
  • 2
  • 5
  • 17
  • I cannot tell from your image where you create the `UIPageViewController` but it looks like you've embedded the `UIPageViewController` within the `UINavigationController` so it will continue to live on after you click the back arrow. If you've add the `UIPageViewController` in `viewDidLoad` you will need to remove it from the `UINavigationController` in `dealloc`. Alternatively, try making the controller visible / invisible in `viewWillAppear` / `viewWillDisappear`. – Robotic Cat May 06 '15 at 00:32
  • Thnx, Check the edit plz @RoboticCat – hamzah May 06 '15 at 11:27
  • OK - you need to create a new question for the crash because it's about a completely different issue. You will also get more views of a new question. You need to add an exception breakpoint to your code and then post the crash output in the question as currently there is not enough info to help you. – Robotic Cat May 06 '15 at 14:14
  • Ok but do you have any idea how to resize the dots? That was part of the question @RoboticCat – hamzah May 06 '15 at 15:26
  • The aim of StackOverflow is to have only one question per post. To answer you, you will need to subclass the `UIPageControl`. See this StackOverflow question: http://stackoverflow.com/q/2673827/558933 – Robotic Cat May 06 '15 at 15:42

0 Answers0