UIPageViewController委托/数据源方法没有触发

时间:2015-04-17 16:23:20

标签: ios objective-c swift uipageviewcontroller

我设置了这样的设置:

UIWindow - > UIViewController - > UIPageViewController - > UIViewController

我已将UIPageViewController中的self的委托和数据源设置为UIViewController,但每次我尝试使用数据更新UIPageViewController时,它只会显示一个图像。我正在将父UIViewController的框架从小到大缩放,或许会影响它?我在其他地方有几乎完全相同的代码,而不是UIWindow并且有效。是否有关于UIWindow s的内容?

任何帮助将不胜感激!

- 编辑 -

好多了一点信息。当用户选择表格视图单元格时,我会调用它。首先,我创建一个新的UIWindow,其大小与当前主UIWindow相同,但位于状态栏的顶部。然后我从故事板创建一个ExpandedViewController,设置一个与UITableViewCell相同的帧大小,给它一些图像加载到UIPageViewController,然后告诉它重新加载它的数据。我还调整了UIPageViewController视图控制器中UIImageView的中心,我可以在以后制作动画,但那是无关紧要的。然后,我将ExpandedViewController的视图添加到UIWindow。这是代码中的内容:

    let cell = tableView.dequeueReusableCellWithIdentifier("aCell", forIndexPath: indexPath) as! ContentTableCell

    var cellRect = tableView.rectForRowAtIndexPath(indexPath)
    var convertedFrame = tableView.convertRect(cellRect, toView: UIApplication.sharedApplication().keyWindow!)

    newWindow = UIWindow(frame: self.view.window!.bounds)
    newWindow.hidden = false
    newWindow.windowLevel = (UIWindowLevelStatusBar + 1)

    var expandedViewController = self.storyboard!.instantiateViewControllerWithIdentifier("ExpandedViewController")! as! ExpandedViewController
    expandedViewController.view.frame = convertedFrame
    expandedViewController.pageImages = imagesForTableView
    expandedViewController.reloadData(indexPath.row)

    var expandedContentViewController = (expandedViewController.pageViewController.viewControllers.last! as! ExpandedContentViewController)

    expandedContentViewController.imageView.frame = self.view.frame
    expandedContentViewController.imageView.center = CGPointMake(cellRect.width/2, cellRect.height/2 + 5)

    newWindow.backgroundColor = UIColor(red: 30/255, green: 1/255, blue: 42/255, alpha: 1)
    newWindow.addSubview(expandedViewController.view)
    newWindow.makeKeyAndVisible()

ExpandedViewControllerViewDidLoad()方法中包含此代码:

    self.view.clipsToBounds = true

    pageImages = []

    // Initialise the Page View Controller from storyboard. Set ourselves as delegate and datasource to it.
    pageViewController = storyboard!.instantiateViewControllerWithIdentifier("ExpandedPageViewController")! as! UIPageViewController
    pageViewController.dataSource = self
    pageViewController.delegate = self

    // Get the View Controller for the first page of the Page View Controller and store in an array
    if let startingViewController: ExpandedContentViewController = viewControllerAtIndex(0) {
        let viewControllers: NSArray = [startingViewController]
        // Set the first page of the Page View Controller
        pageViewController.setViewControllers(viewControllers as [AnyObject], direction: .Forward, animated: false, completion: nil)
    }

    // Make sure the Page View Controller takes up full area of screen
    pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)

    // Add the Page View Controller to current view
    self.addChildViewController(pageViewController)
    self.view.addSubview(pageViewController.view)
    self.pageViewController.didMoveToParentViewController(self)

1 个答案:

答案 0 :(得分:0)

我通过替换

解决了这个问题
newWindow.addSubview(expandedViewController.view)

newWindow.rootViewController = expandedViewController

结果.rootViewController是向UIWindow添加视图的推荐方式