0

I have a PageViewApplication that I am writing and I am oh so nearly there! but I have a problem getting the page number to show as the title of a button I have in a toolbar.

The toolbar is activated when a user taps once on the image in the pageviewcontroller and on this toolbar is a button, which I am told, is the best way to display the page number.

I have written the following where _currentPageNumber is an Integer of the current Index

NSString *strTotalPages = [NSString stringWithFormat:@"%d", NrOfImages];
_pageNumbering.title = [NSString stringWithFormat:@"%d / %@", _currentPageNumber, strTotalPages];   

My issue is where to place this as at the moment it is just showing 0

Any help would be great

Thanks

Justin Erswell
  • 688
  • 7
  • 42
  • 87

3 Answers3

2

I use this function and is working fine

- (NSUInteger)indexOfViewController:(LeafletPageContentViewController *)viewController {   

return [self.modelArray indexOfObject:viewController.dataObject]; }

modelArray is the array with the data of each view

Then, when I want to know the current index use this

ClassOfMyViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0];


NSUInteger retreivedIndex = [self indexOfViewController:currentViewController]; 
jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
0

If you're changing the title of a button on a toolbar then you will need to remove/re-create and add the button to the toolbar as it isn't quite as simple as just changing the title of the button with a string value.

Essentially redrawing it should solve the issue.

Brayden
  • 1,795
  • 14
  • 20
  • THanks for this is there a way to show the current page number on this toolbar when it is called? – Justin Erswell May 17 '12 at 11:38
  • When you redraw it you can simply do something like this: NSString *string = [NSString stringWithFormat:@"Page: %d", pageController.currentPage]; It may be slightly different than "currentPage" but I can't verify quite yet. – Brayden May 22 '12 at 18:54
0

I struggled with this problem, but the pageViewController doesn't provide a method to retrieve the current page. So, if you use the method pageControllerAfterPageController or pageControllerBeforePageController you should get a wrong page number: in fact, if you swipe your finger to change page, but you don't complete the swipe, the page showed remains the same, but your counter show the previous or next page number.

So, you can try to use viewDidLoad method of your contentViewController for update the counter and the button !

Fry
  • 6,235
  • 8
  • 54
  • 93