使用UIPageView图像打开ViewController w / NavigationController

我正在尝试在UIPageView中打开三个不同的NavigationController 。 这是我现在的布局。 我将三个自定义Segue连接到每个NavigationController并在ContentViewController下,我添加了以下@IBAction方法:

 @IBAction func navJns(sender: AnyObject?){ let storyboard = UIStoryboard(name: "Nav", bundle: nil) let controller = storyboard.instantiateViewControllerWithIdentifier("Jeans") as! Jeans self.modalPresentationStyle = UIModalPresentationStyle.Custom presentViewController(controller, animated: true, completion: nil) } @IBAction func navBlusas(sender: AnyObject?){ let storyboard = UIStoryboard(name: "Nav", bundle: nil) let controller = storyboard.instantiateViewControllerWithIdentifier("Blusas") as! Blusas self.modalPresentationStyle = UIModalPresentationStyle.Custom presentViewController(controller, animated: true, completion: nil) } @IBAction func navLeggings(sender: AnyObject?){ let storyboard = UIStoryboard(name: "Nav", bundle: nil) let controller = storyboard.instantiateViewControllerWithIdentifier("Leggings") as! Leggings self.modalPresentationStyle = UIModalPresentationStyle.Custom presentViewController(controller, animated: true, completion: nil) } 

并根据viewDidLoad方法:

 var tapGesturePageView = UITapGestureRecognizer(target: self, action: "navJns:"); self.imageView.addGestureRecognizer(tapGesturePageView) var tapGesturePageView2 = UITapGestureRecognizer(target: self, action: "navBlusas:"); self.imageView.addGestureRecognizer(tapGesturePageView2) var tapGesturePageView3 = UITapGestureRecognizer(target: self, action: "navLeggings:"); self.imageView.addGestureRecognizer(tapGesturePageView3) 

当我编译和运行的应用程序,它显示在PageView中的三个图像,但没有发生。

任何意见将是有益的!

这是其余的代码:

ContentViewController.swift

 import UIKit class ContentViewController: UIViewController { @IBOutlet weak var imageView: UIImageView! var pageIndex: Int! var imageFile: String! override func viewDidLoad() { super.viewDidLoad() self.imageView.image = UIImage(named: self.imageFile) var tapGesturePageView = UITapGestureRecognizer(target: self, action: "navJns:"); self.imageView.addGestureRecognizer(tapGesturePageView) var tapGesturePageView2 = UITapGestureRecognizer(target: self, action: "navBlusas:"); self.imageView.addGestureRecognizer(tapGesturePageView2) var tapGesturePageView3 = UITapGestureRecognizer(target: self, action: "navLeggings:"); self.imageView.addGestureRecognizer(tapGesturePageView3) } @IBAction func navJns(sender: AnyObject?){ let storyboard = UIStoryboard(name: "Nav", bundle: nil) let controller = storyboard.instantiateViewControllerWithIdentifier("Jeans") as! Jeans self.modalPresentationStyle = UIModalPresentationStyle.Custom presentViewController(controller, animated: true, completion: nil) } @IBAction func navBlusas(sender: AnyObject?){ let storyboard = UIStoryboard(name: "Nav", bundle: nil) let controller = storyboard.instantiateViewControllerWithIdentifier("Blusas") as! Blusas self.modalPresentationStyle = UIModalPresentationStyle.Custom presentViewController(controller, animated: true, completion: nil) } @IBAction func navLeggings(sender: AnyObject?){ let storyboard = UIStoryboard(name: "Nav", bundle: nil) let controller = storyboard.instantiateViewControllerWithIdentifier("Leggings") as! Leggings self.modalPresentationStyle = UIModalPresentationStyle.Custom presentViewController(controller, animated: true, completion: nil) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } 

ViewController.swift

 import UIKit class ViewController: UIViewController, UIPageViewControllerDataSource { var pageViewController: UIPageViewController! var pageImages: NSArray! override func viewDidLoad() { super.viewDidLoad() self.pageImages = NSArray(objects: "jeans.png", "blusas.png", "leggings.png") self.pageViewController = self.storyboard?.instantiateViewControllerWithIdentifier("PageViewController") as! UIPageViewController self.pageViewController.dataSource = self var startVC = self.viewControllerAtIndex(0) as ContentViewController var viewControllers = NSArray(object: startVC) self.pageViewController.setViewControllers(viewControllers as [AnyObject], direction: .Forward, animated: true, completion: nil) self.pageViewController.view.frame = CGRectMake(0, 30, self.view.frame.width, self.view.frame.size.height - 60) self.addChildViewController(self.pageViewController) self.view.addSubview(self.pageViewController.view) self.pageViewController.didMoveToParentViewController(self) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func viewControllerAtIndex(index: Int) -> ContentViewController? { if index >= self.pageImages.count { return nil } var vc: ContentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ContentViewController") as! ContentViewController vc.imageFile = self.pageImages[index] as! String vc.pageIndex = index return vc } // MARK: - Page View Controller Data Source func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? { var vc = viewController as! ContentViewController var index = vc.pageIndex as Int if (index == 0) || (index == NSNotFound) { return nil } index-- return self.viewControllerAtIndex(index) } func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? { var vc = viewController as! ContentViewController var index = vc.pageIndex as Int if (index == NSNotFound) { return nil } index++ return self.viewControllerAtIndex(index) } func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int { return 0 } }