[英]iOS Swift Page View Controller
Hi guys I got 4 errors at; 大家好,我有4个错误;
import UIKit
class ViewController: UIViewController, UIPageViewControllerDataSource{ // error1: Expected ',' separator
here is the first error with the error message: Expected ',' separator 这是第一个带有错误消息的错误:预期的','分隔符
//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: "dummying - men","dummying - women")
self.pageViewController = self.storyboard?.instantiateViewControllerWithIdentifier("PageViewController") as! UIPageViewController
self.pageViewController.dataSource = self //error2: Cannot assign a value of type 'ViewController' to a value of type 'UIPageViewControllerDataSource?'
here is the second error with the error message: Cannot assign a value of type 'ViewController' to a value of type 'UIPageViewControllerDataSource?' 这是带有错误消息的第二个错误:无法将类型“ ViewController”的值分配给类型“ UIPageViewControllerDataSource?”的值
var startVC = self.viewControllerAtIndex(0) as ContentMenuViewController
var viewControllers = NSArray(object: startVC)
self.pageViewController.setViewControllers(viewControllers, direction: Forward animated: true, completion: nil) //error2: Use of unresolved identifier 'Forward'
here is the second error with the error message: Use of unresolved identifier 'Forward' 这是错误消息的第二个错误:使用未解决的标识符“转发”
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
}
//Page View Controller Data Source
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)//error3: Expected expression after operator
here is the second error with the error message: Expected expression after operator { return nil } return self.viewControllerAtIndex(index) } 这是错误消息的第二个错误:运算符{return nil}之后的期望表达式return self.viewControllerAtIndex(index)}
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
return self.pageTitles.count
}
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
return 0
}
}
thanks for the help guys.. 谢谢你们的帮助。
EDIT: 编辑:
Well, the second error is because of the first one. 好吧,第二个错误是由于第一个错误。 The first error makes no sense at all, I would recommend you to
Product -> Clean
. 第一个错误根本没有意义,我建议您选择
Product -> Clean
。
And the other 2 errors, try writing it this way .Forward
(That Forward has to be inside an enum, I hope there's somewhere in your code you haven't posted). 还有另外两个错误,请尝试用这种方式编写。
.Forward
(转发必须在枚举内,我希望您的代码中有未发布的地方)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.