我在下面的代码中有2个错误,原因相同。我该如何解决这个问题?
错误说"运算符后的预期表达式"在最后两个函数中的return viewControllerAtIndex(index)
行。
func viewControllerAtIndex(index: Int) -> WalkthroughContentViewController? {
if index == NSNotFound || index < 0 || index >= pageHeadings.count {
return nil
}
// Creating a new view controller and passing the data
if let pageContentViewController = storyboard?.instantiateViewControllerWithIdentifier("WalkthroughContentViewController") as? WalkthroughContentViewController {
pageContentViewController.imageFile = pageImages[index]
pageContentViewController.heading = pageHeadings[index]
pageContentViewController.content = pageContent[index]
pageContentViewController.index = index
return pageContentViewController
}
return nil
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
var index = (viewController as! WalkthroughContentViewController).index
index ++
return viewControllerAtIndex(index)
}
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
var index = (viewController as! WalkthroughContentViewController).index
index --
return viewControllerAtIndex(index)
}
这是来自Simon Ng的Swift Book。
答案 0 :(得分:2)
问题是目标和后缀增量/减量运算符之间的空间。应为index++
和index--
。