UItableview中的多个页面视图控制器,当我选择或滑动页面时,我没有获得单元索引路径?

时间:2017-09-15 08:31:11

标签: ios swift swift3 uipageviewcontroller

  • 在UITableview中,有多个页面视图控制器和不同的内容,如数组。
  • 第一次显示正常,因为我第一次为所有单元格(数组)传递index = 0。
  • 但是例如在tableview中滚动和向下滚动之后,在当前地址部分:有3页,这里我想根据单元索引路径数组传递受尊重的数组,但我无法获取单元格(页)索引路径
  • 如果我知道基于单元索引路径,我会将尊重的数据传递给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
        }
    

enter image description here

0 个答案:

没有答案