- Navigation Controller - Parent
- Page ViewController - Child of Navigation Controller
- DetailsViewController - ViewController to be displayed in PageViewController.
My DetailsViewController contains scrollview and array of detailsviewController with different data is passed to pageviewcontroller.
The problem is only first viewController of pageviewcontroller is shown under navigartionbar and its scrollview is working.
But rest are pushed under navigation controller and scrollview is not working.
1st image : First Details view controller working properly
2nd Image : Next DetailsViewController from dataset when i swipe. Here the content is pushed under navigation bar and scrollview not working
After doing further research i found that navigationcontroller property of rest of detailsviewcontroller except first is nil.
//
// PagerViewController.swift
//
//
// Created by Admin on 13/07/16.
//
//
import UIKit
class PagerViewController: UIPageViewController {
var result = Array<SearchResult>();
var mainStoryBoard = UIStoryboard(name: "Main", bundle: nil);
var resultSet = [UIViewController]();
var currentIndex = 0;
// MARK: - Life cycle Methods
override func viewDidLoad() {
super.viewDidLoad();
dataSource = self;
delegate = self;
generateDatset();
let initialViewController = resultSet[currentIndex] ;
let viewControllers = NSArray(objects : initialViewController);
setViewControllers(viewControllers as? [UIViewController], direction: .Forward, animated: true, completion: nil);
self.navigationController!.edgesForExtendedLayout = .None;
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Dataset Initialisation
func generateDatset() {
for searchResult in result {
let viewController = mainStoryBoard.instantiateViewControllerWithIdentifier(Constants.STORYBOARDUIFIELDS.DETAILSVIEWCONTROLLER) as? DetailsViewController;
viewController?.searchResult = searchResult;
resultSet.append(viewController!)
}
}
}
// MARK: - UIPageViewControllerDataSource
extension PagerViewController : UIPageViewControllerDataSource {
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = resultSet.indexOf(viewController) else {
return nil;
}
let nextIndex = viewControllerIndex + 1;
guard resultSet.count > nextIndex else {
return nil;
}
currentIndex = nextIndex;
return resultSet[nextIndex];
}
func scrollToNext(viewControllers : UIViewController) {
setViewControllers([viewControllers], direction: .Forward, animated: true, completion: nil)
}
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = resultSet.indexOf(viewController) else {
return nil;
}
let previousIndex = viewControllerIndex - 1;
guard previousIndex >= 0 else {
return nil;
}
currentIndex = previousIndex;
return resultSet[previousIndex];
}
}
//
// DetailsViewController.swift
//
//
// Created by Admin on 13/07/16.
//
//
import UIKit
class DetailsViewController: UIViewController {
var searchResult : SearchResult? = nil;
@IBOutlet weak var ShoeImageView: UIImageView!
@IBOutlet weak var DnsItemCodeLabel: UILabel!
@IBOutlet weak var GeneralDetailsCollView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
//print(navigationController)
DnsItemCodeLabel.text = "\(searchResult!.DNS!) - \(searchResult!.ItemCode!)";
// converting base64encoded image into nsdata and then to ui image
let image = UIImage(data: NSData(base64EncodedString: searchResult!.Image!, options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters)!)
ShoeImageView.image = image;
// Assigning source to CollectionView
GeneralDetailsCollView.dataSource = self;
print(navigationController)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
// MARK: - UICollectionViewDataSource
extension DetailsViewController : UICollectionViewDataSource {
// returns the number of items
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return (searchResult!.summaryItems?.count)!;
}
//return the cell for given position
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(Constants.STORYBOARDUIFIELDS.GENRAL_DETAILS_CELL, forIndexPath: indexPath) as! GeneralDetailsCell
if let data = searchResult?.summaryItems![indexPath.row] {
cell.TitleLable.text = data.Title!;
cell.ValueLabel.text = data.Value!;
}
return cell
}
}