我正在使用PageViewController,然后我为PageViewController声明了数据源,并且当实现所需的方法时,我在使用as downcast时出现错误,它说“correctViewController不是类型。”
import UIKit
class HarishPageViewController: UIPageViewController, UIPageViewControllerDataSource {
override func viewDidLoad() {
super.viewDidLoad()
self.dataSource = self
// Do any additional setup after loading the view.
}
let pageTitles = ["HarishIntroduction", "HarishPlaces", "WyomingSeminary", "AppleTree", "KearneyHighSchool", "MosconeCenter"]
let viewControllerArray: NSArray = [HarishIntroduction(), HarishPlaces(), WyomingSeminary(), AppleTree(), KearneyHighSchool(), MosconeCenter()]
var index = 0
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
if index == 0 {
return nil
}
else {
index--
let page = pageTitles[index]
let correctViewController: UIViewController = viewControllerArray[index] as! UIViewController
let vc = harishStoryboard.instantiateViewControllerWithIdentifier(page) as correctViewController
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
我尝试了很多不同的方法,但我只是无法摆脱as旁边的错误。有什么想法吗?
答案 0 :(得分:2)
它不是类型或类。您正在尝试向下转换为变量。
as
之后只需编写控制器的类