Skip to content

Instantly share code, notes, and snippets.

@psugihara
Created November 13, 2014 07:11
Show Gist options
  • Save psugihara/ca743657a53eeb6c34a0 to your computer and use it in GitHub Desktop.
Save psugihara/ca743657a53eeb6c34a0 to your computer and use it in GitHub Desktop.
UIPageViewController in Swift using Interface Builder
//The MIT License (MIT)
//
//Copyright (c) 2014 Open Listings
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
//
// OLHelpPageViewController.swift
// OpenListings
//
// Created by Peter Sugihara on 11/12/14.
import UIKit
class OLHelpPageViewController: UIPageViewController, UIPageViewControllerDataSource {
let pageContentViewControllers = [
UIViewController(nibName: "OLHelpPage1", bundle: nil),
UIViewController(nibName: "OLHelpPage2", bundle: nil),
UIViewController(nibName: "OLHelpPage3", bundle: nil)
]
override func viewDidLoad() {
super.viewDidLoad()
self.dataSource = self
self.setViewControllers([pageContentViewControllers.first!], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)
}
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
return pageContentViewControllers.count
}
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
return 0;
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
let index = find(pageContentViewControllers, viewController)
if index == nil || index! + 1 == pageContentViewControllers.count {
return nil
} else {
return pageContentViewControllers[index! + 1]
}
}
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
let index = find(pageContentViewControllers, viewController)
if index == nil || index! == 0 {
return nil
} else {
return pageContentViewControllers[index! - 1]
}
}
}
@sunilkumarj
Copy link

I am using in the same way.. In the xib if i am using any outlet I am getting error.. Can any one suggest me for this problem.. When I call directly view controller its working.. If call from xib inside pageViewcontroller I am getting this error.

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ATLLocal.ViewController 0x7f8e446103e0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key fullName.'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment