通过UIPageController VC segues覆盖UITableView上的滑动操作

时间:2015-04-05 09:44:36

标签: uitableview swift uipageviewcontroller

swift 中,我目前正致力于使用UIPageViewController来设置我的VC,当您向左或向右滑动时,它会更改VC。在我的View Controllers之一中,存在一个表格视图,如果您在该行上滑动,则会有选项。我的问题是,当我在表格的行上滑动时,它会切换到我的View Controller。我想覆盖它,以便它在VC滑动之前显示行动作。我下面的代码是第一个VC。 PS:如果您需要我的代码用于我的表格,请评论它!感谢

import UIKit


class ViewController: UIViewController, UIPageViewControllerDataSource {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.


    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.

    }

    var myViewControllers = Array(count: 4, repeatedValue:UIViewController())

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
        let pvc = segue.destinationViewController as UIPageViewController

        pvc.dataSource = self

        let storyboard = UIStoryboard(name: "Main", bundle: nil);

        var vc0 = storyboard.instantiateViewControllerWithIdentifier("FirstViewController") as UIViewController
        var vc1 = storyboard.instantiateViewControllerWithIdentifier("SecondViewController") as UIViewController
        var vc2 = storyboard.instantiateViewControllerWithIdentifier("ThirdViewController") as UIViewController
        var vc3 = storyboard.instantiateViewControllerWithIdentifier("FourthViewController") as UIViewController

        self.myViewControllers = [vc0, vc1, vc2, vc3]

        pvc.setViewControllers([myViewControllers[1]], direction:.Forward, animated:false, completion:nil)

        println("Loaded")
    }

    func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
        var currentIndex =  find(self.myViewControllers, viewController)!+1
        if currentIndex >= self.myViewControllers.count {
            return nil
        }
        return self.myViewControllers[currentIndex]
    }

    func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
        var currentIndex =  find(self.myViewControllers, viewController)!-1
        if currentIndex < 0 {
            return nil
        }
        return self.myViewControllers[currentIndex]
    }

}

1 个答案:

答案 0 :(得分:0)

tableView是否占用了视图中的所有空间?让我们试试

override func scrollViewDidScroll(scrollView: UIScrollView) {
}