Hi Swift类型不符合协议NilliteralConvertible

时间:2015-08-07 13:01:04

标签: ios swift

//For Navigation Bar Tint and BG Color
var NavBarBGColor = CommonUtilities.RGBColor("#2574A9")
var NavBarTintColor = UIColor.whiteColor()

var pageViewController: UIPageViewController!
var pageTitles: NSArray!
var pageImages: NSArray!

@IBOutlet weak var Open: UIBarButtonItem!
override func viewDidLoad() {
  //Navigation Bar Tint and BG Color
    self.navigationController?.navigationBar.tintColor = NavBarTintColor
    self.navigationController?.navigationBar.barTintColor = NavBarBGColor

    super.viewDidLoad()

    //Menu Button Click
    Open.target = self.revealViewController()
    Open.action = Selector("revealToggle:")

    //Pan Gesture Recognizer for page navigation
    self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())

    //Page View Controller for Men
    self.pageTitles = NSArray(objects: "Try","And")
    self.pageImages = NSArray(objects: "page1","page2")

    self.pageViewController = self.storyboard?.instantiateViewControllerWithIdentifier("PageViewController") as! UIPageViewController


    self.pageViewController.dataSource = self.pageViewController.dataSource

    /*var startVC = self.viewControllerIndex(0) as ContentMenuViewController
    var viewControllers = NSArray(object: startVC)

    self.pageViewController.ViewControllers(viewControllers, direction: .Forward, animated: true, completion: nil)*/

    self.pageViewController.view.frame = CGRectMake(0, 30, self.view.frame.width, self.view.frame.size.height - 60)

    self.addChildViewController(self.pageViewController)
    self.view.addSubview(self.pageViewController.view)
    self.pageViewController.didMoveToParentViewController(self)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()


}
@IBAction func MenuRestartBtn(sender: AnyObject) {
}

func viewControllerAtIndex(index: Int) -> ContentMenuViewController
{
    if ((self.pageTitles.count == 0)) || (index >= self.pageTitles.count)
    {
        return ContentMenuViewController()
    }

    var vc: ContentMenuViewController = self.storyboard?.instantiateViewControllerWithIdentifier("") as! ContentMenuViewController


    vc.imageFile = self.pageImages[index] as! String
    vc.titleText = self.pageTitles[index] as! String
    vc.pageIndex = index

    return vc
}

//页面视图控制器数据源     func pageViewController(pageViewController:UIPageViewController,viewControllerAfterViewController viewController:UIViewController) - >的UIViewController? {         var vc = viewController as! ContentMenuViewController         var index = vc.pageIndex as Int

    if (index == 0 || index == NSNotFound)
    {
        return nil
    }

    index--
    return self.viewControllerAtIndex(index)

    }

func pageViewController(pageController:UIPageViewController,ViewControllerAfterViewController viewController:UIViewController) - >的UIViewController {

var vc = viewController as! ContentMenuViewController
var index = vc.pageIndex as Int

if (index == NSNotFound){
    return nil;
}

index ++
if (index == self.pageTitles.count){
    return nil
}


return self.viewControllerAtIndex(index)

}

func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
    return self.pageTitles.count

}

func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
return 0

} }

1 个答案:

答案 0 :(得分:-1)

当函数返回你试图做的UIViewController时,你不能返回nil:

func pageViewController(pageController: UIPageViewController, ViewControllerAfterViewController viewController: UIViewController) -> UIViewController

将以上内容替换为:

func pageViewController(pageController: UIPageViewController, ViewControllerAfterViewController viewController: UIViewController) -> UIViewController?