title: How do I get the index out of the optional func didMoveToPage?
body: <p>I am using uacaps/CAPSPageMenu in my app and I cannot figure out how to get the number of the active page so I can show a webpage corresponding to the page. In the code CAPSPageMenu.swift the following code is used.</p>
  
  <pre><code>import UIKit
  
  @objc public protocol CAPSPageMenuDelegate {
  // MARK: - Delegate functions
  
  optional func willMoveToPage(controller: UIViewController, index: Int)
  optional func didMoveToPage(controller: UIViewController, index: Int)
  }
  </code></pre>
  
  <p>I think the index: Int part in the optional func didMoveToPage is giving me a number of the current page. Is this right? How do I get that index number in the ViewController.swift code?</p>
  
  <p><strong>EDIT</strong><br>
  In CAPSPageMenu I found this code.  </p>
  
  <pre><code>public func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
      if scrollView.isEqual(controllerScrollView) {
          // Call didMoveToPage delegate function
          let currentController = controllerArray[currentPageIndex]
          delegate?.didMoveToPage?(currentController, index: currentPageIndex)
  </code></pre>
  
  <p>The ViewController.swift code as shown below.  </p>
  
  <pre><code>//
  //  ViewController.swift
  //  PageMenuDemoStoryboard
  //
  //  Created by Niklas Fahl on 12/19/14.
  //  Copyright (c) 2014 CAPS. All rights reserved.
  //
  
  import UIKit
  
  
  var websiteArray = ["http://website_0", "http://website_1", "http://website_2"]
  
  
  //class ViewController: UIViewController {
  class ViewController: UIViewController,CAPSPageMenuDelegate {
  
  var pageMenu : CAPSPageMenu?
  var pageNumber = 0
  
  @IBOutlet weak var showWebsite: UIWebView!
  
  override func viewDidAppear(animated: Bool) {
      super.viewDidAppear(animated)
  
  
      // MARK: - UI Setup
      self.title = "App Title"
      self.navigationController?.navigationBar.barTintColor = UIColor(red: 30.0/255.0, green: 30.0/255.0, blue: 30.0/255.0, alpha: 1.0)
      self.navigationController?.navigationBar.shadowImage = UIImage()
      self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
      self.navigationController?.navigationBar.barStyle = UIBarStyle.Black
      self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
      self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.orangeColor()]
  
      self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "&lt;-", style: UIBarButtonItemStyle.Done, target: self, action: "didTapGoToLeft")
      self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "-&gt;", style: UIBarButtonItemStyle.Done, target: self, action: "didTapGoToRight")
  
  
      // MARK: - Scroll menu setup
  
      // Initialize view controllers to display and place in array
      var controllerArray : [UIViewController] = []
  
      let controller1 : TestCollectionViewController = TestCollectionViewController(nibName: "TestCollectionViewController", bundle: nil)
      controller1.title = "Item_0"
      controller1.photoNameArray = ["Item_0.png"]
      controllerArray.append(controller1)
      let controller2 : TestCollectionViewController = TestCollectionViewController(nibName: "TestCollectionViewController", bundle: nil)
      controller2.title = "Item_1"
      controller2.photoNameArray = ["Item_1.png"]
      controllerArray.append(controller2)
      let controller3 : TestCollectionViewController = TestCollectionViewController(nibName: "TestCollectionViewController", bundle: nil)
      controller3.title = "Item_2"
      controller3.photoNameArray = ["Item_2.png"]
      controllerArray.append(controller3)
  
  
      // Customize menu (Optional)
      let parameters: [CAPSPageMenuOption] = [
          .ScrollMenuBackgroundColor(UIColor(red: 30.0/255.0, green: 30.0/255.0, blue: 30.0/255.0, alpha: 1.0)),
          .ViewBackgroundColor(UIColor(red: 20.0/255.0, green: 20.0/255.0, blue: 20.0/255.0, alpha: 1.0)),
          .SelectionIndicatorColor(UIColor.orangeColor()),
          .BottomMenuHairlineColor(UIColor(red: 70.0/255.0, green: 70.0/255.0, blue: 80.0/255.0, alpha: 1.0)),
          .MenuItemFont(UIFont(name: "HelveticaNeue", size: 13.0)!),
          .MenuHeight(30.0),
          .MenuItemWidth(90.0),
          .CenterMenuItems(true)
      ]
  
      // Initialize scroll menu
      pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, self.view.frame.height * 0.71, self.view.frame.width, self.view.frame.height * 0.33), pageMenuOptions: parameters)
  
      self.addChildViewController(pageMenu!)
      self.view.addSubview(pageMenu!.view)
  
      pageMenu!.didMoveToParentViewController(self)
  
      pageMenu!.delegate = self
  
  
      func willMoveToPage(controller: UIViewController, index: Int) {
          let subview=controller as! ViewController
          subview.pageNumber=index;
      }
  
  }
  
  
  func didTapGoToLeft() {
      var currentIndex = pageMenu!.currentPageIndex
  
      if currentIndex &gt; 0 {
          pageMenu!.moveToPage(currentIndex - 1)
      }
      setWebPage()
  }
  
  
  func didTapGoToRight() {
      var currentIndex = pageMenu!.currentPageIndex
  
      if currentIndex &lt; pageMenu!.controllerArray.count {
          pageMenu!.moveToPage(currentIndex + 1)
      }
      setWebPage()
  }
  
  
  func setWebPage() {
      var currentIndex = pageMenu!.currentPageIndex
      switch currentIndex {
      case 0:
          let url = NSURL (string: "\(websiteArray[0])");
          let requestObj = NSURLRequest(URL: url!);
          showWebsite.loadRequest(requestObj);
          break
  
      case 1:
          let url = NSURL (string: "\(websiteArray[1])");
          let requestObj = NSURLRequest(URL: url!);
          showWebsite.loadRequest(requestObj);
          break
  
      case 2:
          let url = NSURL (string: "\(websiteArray[2])");
          let requestObj = NSURLRequest(URL: url!);
          showWebsite.loadRequest(requestObj);
          break
  
      default:
          break
      }
  }
  
  
  // MARK: - Container View Controller
  override func shouldAutomaticallyForwardAppearanceMethods() -&gt; Bool {
      return true
  }
  
  override func shouldAutomaticallyForwardRotationMethods() -&gt; Bool {
      return true
  }
  }
  </code></pre>
  
  <p>When I tap the buttons it is working like it should. The navigation bar shows the active page and the picture (collectionViewController) that belongs to the active page is shown and also the webpage that belongs to the active page is shown. But I do not want to use the buttons. I want to use the collectionViewController so that when I swipe the image to the next page the new image is shown (this is working already) and the corresponding webpage also (this is not working because of not setting the <em>pageMenu!.currentPageIndex</em>).<br>
  How to activate the didTapGoToLeft and Right methods when I swipe the picture?</p>