如果我知道基于单元索引路径,我会将尊重的数据传递给contentpageviewcontroller。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell: UITableViewCell!
cell = tableView.dequeueReusableCell(withIdentifier: "pageviewCell", for: indexPath)
self.pageViewController = (storyboard?.instantiateViewController(withIdentifier: "PageViewController"))! as! UIPageViewController
self.pageViewController.delegate = self
self.pageViewController.dataSource = self
self.pageViewController.title = "\(indexPath.row-1)"
pageViewController.setViewControllers([getViewControllerAtIndex(index: 0, indexPath: indexPath.row-1)], direction: UIPageViewControllerNavigationDirection.forward, animated: false, completion: nil)
pageViewController.view.frame = CGRect(x: 5, y: 5, width: cell.contentView.frame.size.width-10, height: cell.contentView.frame.size.height-10)
self.addChildViewController(pageViewController)
cell.contentView.addSubview(pageViewController.view)
self.pageViewController.didMove(toParentViewController: self)
cell.backgroundColor = UIColor.gray
return cell
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController?
{
let pageContent: ProfilePageContentVC = viewController as! ProfilePageContentVC
var index = pageContent.pageIndex
if ((index == 0) || (index == NSNotFound))
{
return nil
}
index -= 1;
return getViewControllerAtIndex(index: index, indexPath: Int(pageViewController.title!)!)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController?
{
let pageContent: ProfilePageContentVC = viewController as! ProfilePageContentVC
var index = pageContent.pageIndex
if (index == NSNotFound)
{
return nil;
}
index += 1;
let val: NSString = pageListCountChkDict.value(forKey: self.pageViewController.title!) as! NSString
//if (index == arrPageTitle.count)
if (index == val.integerValue)
{
return nil;
}
return getViewControllerAtIndex(index: index, indexPath: Int(pageViewController.title!)!)
}
func getViewControllerAtIndex(index: NSInteger, indexPath: NSInteger) -> ProfilePageContentVC {
let pageContentViewController = (storyboard?.instantiateViewController(withIdentifier: "ProfilePageContentVC"))! as! ProfilePageContentVC
pageContentViewController.pageIndex = index
let pageContentDict = NSMutableDictionary()
let pageContentFinalArray = NSMutableArray()
if objModel.finalDict.allKeys[indexPath] as! String == "EMPOFFHR" {
pageContentFinalArray.add(pageContentDict)
pageContentViewController.pageContentFinalArray = pageContentFinalArray as NSArray
let pageTitleArray = ["HR Details"]
pageContentViewController.pageTitleArray = pageTitleArray as NSArray
}
func presentationCount(for pageViewController: UIPageViewController) -> Int {
let val: NSString = pageListCountChkDict.value(forKey: self.pageViewController.title!) as! NSString
print("presentationCount :\(self.pageViewController.title!)")
print("presentationCount :\(val)")
return val.integerValue
}
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
return 0
}