NavigationController中的PageViewController子句在ios中滚动问题的ViewController

NavigationController中的PageViewController子句在ios中滚动问题的ViewController,第1张

概述>导航控制器 – 父 >页面ViewController – 导航控制器的子项 > DetailsViewController – 要在PageViewController中显示的ViewController. 我的DetailsViewController包含scrollview和detailsviewController数组,不同的数据被传递给pageviewcontroller. 问题只是第 >导航控制器 – 父
>页面VIEwController – 导航控制器的子项
> DetailsVIEwController – 要在PageVIEwController中显示的VIEwController.

我的DetailsVIEwController包含scrollvIEw和detailsvIEwController数组,不同的数据被传递给pagevIEwcontroller.

问题只是第一个vIEwvIEw控件的pagevIEw控件显示在navigartionbar下,其scrollvIEw正在工作.

但是休息是在导航控制器下推动的,并且scrollvIEw不起作用.

1st image:First Details视图控制器正常工作

第二张图像:当我滑动时,数据集中的下一个DetailsVIEwController.这里的内容在导航栏下滚动,滚动视图无效

经过进一步研究后,我发现除了first之外,其余detailsvIEwcontroller的navigationcontroller属性为nil.

////  PagerVIEwController.swift//  ////  Created by admin on 13/07/16.// //import UIKitclass 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: - UIPageVIEwControllerDataSourceextension 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],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 UIKitclass 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: - UICollectionVIEwDataSourceextension 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    }}
解决方法 这曾经发生在我身上,所以我当时做了什么,我添加了一个普通的VIEwController并使其成为NavigationVIEwController的根控制器.现在,我在这个VIEwController中添加了PageVIEwController.然后一切都很好.简而言之,尽管使NavigationController成为父控制器,但将导航控制器的根VIEwController作为PageVIEwController的父级.

我在vIEwController.swift(导航控制器的根视图控制器)中创建了pageVIEwController实例,VIEwController.swift看起来像:

import UIKitclass VIEwController: UIVIEwController,UIPageVIEwControllerDataSource,UIPageVIEwControllerDelegate {    var pageVIEwController:UIPageVIEwController?    var presentIndex = 0    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        self.pageVIEwController = UIPageVIEwController.init(TransitionStyle: UIPageVIEwControllerTransitionStyle.Scroll,navigationorIEntation: UIPageVIEwControllerNavigationorIEntation.Horizontal,options: nil)        self.pageVIEwController!.dataSource=self        let initialVIEwController:DetailVIEwController = self.giverequiredVIEwController(1)        let vIEwControllerArray:NSArray = [initialVIEwController]        self.pageVIEwController?.setVIEwControllers(vIEwControllerArray as! [DetailVIEwController],direction: UIPageVIEwControllerNavigationDirection.Forward,completion: nil)        self.addChildVIEwController(self.pageVIEwController!)        self.vIEw.addSubvIEw((self.pageVIEwController?.vIEw)!)        self.pageVIEwController?.dIDMovetoParentVIEwController(self)        self.vIEw.backgroundcolor=UIcolor.blackcolor()        self.navigationController?.navigationbar.barTintcolor=UIcolor.redcolor()        // Do any additional setup after loading the vIEw,typically from a nib.    }    overrIDe func vIEwWillLayoutSubvIEws() {        let frame = CGRectMake(0,64,self.vIEw.frame.wIDth,self.vIEw.frame.height-40)        self.pageVIEwController?.vIEw.frame = frame    }    func pageVIEwController(pageVIEwController: UIPageVIEwController,vIEwControllerBeforeVIEwController vIEwController: UIVIEwController) -> UIVIEwController? {        presentIndex = (vIEwController as! DetailVIEwController).index!        if presentIndex==0{            return nil        }       return self.giverequiredVIEwController(presentIndex-1)    }    func giverequiredVIEwController(index:NSInteger) -> DetailVIEwController {        let detailVIEwController = DetailVIEwController(nibname: "DetailVIEwController",bundle: nil)        detailVIEwController.index = index        return detailVIEwController    }    func pageVIEwController(pageVIEwController: UIPageVIEwController,vIEwControllerAfterVIEwController vIEwController: UIVIEwController) -> UIVIEwController? {        presentIndex = (vIEwController as! DetailVIEwController).index!        if presentIndex==1{            return nil        }        return self.giverequiredVIEwController(presentIndex+1)    }    overrIDe func dIDReceiveMemoryWarning() {        super.dIDReceiveMemoryWarning()        // dispose of any resources that can be recreated.    }}

我提供了DetailVIEwController的索引,这个索引基本上会告诉我正在呈现哪个页面,我会相应地调整我的视图.现在我已经更改了视图更改的背景颜色.
目前只有两页,你可以拥有尽可能多的页面.

DetailVIEwController.swift代码是这样的,

import UIKitclass DetailVIEwController: UIVIEwController {    var index:NSInteger?    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        if index==0{            self.vIEw.backgroundcolor=UIcolor.bluecolor()        }else{            self.vIEw.backgroundcolor = UIcolor.graycolor()        }        // Do any additional setup after loading the vIEw.    }    overrIDe func dIDReceiveMemoryWarning() {        super.dIDReceiveMemoryWarning()        // dispose of any resources that can be recreated.    }}

完整的代码可以在link中找到

总结

以上是内存溢出为你收集整理的NavigationController中的PageViewController子句在ios中滚动问题的ViewController全部内容,希望文章能够帮你解决NavigationController中的PageViewController子句在ios中滚动问题的ViewController所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1049935.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存