我正在尝试将导入的解析信息添加到pageviewcontroller,但它会一直崩溃,因为所有数组都是nil,而第二个函数是在早期调用的。我该如何解决这个问题?
override func viewDidLoad() {
super.viewDidLoad()
self.retrieveInfo() { () -> () in
self.testRetrieveInfo()
}
}
func retrieveinfos(handleComplete:(()->())){
let query = PFQuery(className: "Animals")
query.findObjectsInBackgroundWithBlock { (objects:[PFObject]?, error: NSError?) in
if(error == nil){
for object in objects!{
if let importname = object["Name"] as? String{
self.name.append(importname)
print(self.name)
}
}
}else{
print(error)
}
}
handleComplete()
}
}
func testRetrieveInfo(){
//Setup here the PageViewController
self.pageViewController.storyboard?.instantiateViewControllerWithIdentifier("PageVC") as? UIPageViewController //Crashes here, with fatal error fatal error: unexpectedly found nil while unwrapping an Optional value, I checked the logs and all the arrays are empty
self.pageViewController.dataSource = self
var startVC = self.viewControllerAtIndex(0) as? Animal
var viewControllers = NSArray(object: startVC!)
self.pageViewController.setViewControllers(viewControllers as? [UIViewController], direction: .Forward , animated: true, completion: nil)
self.pageViewController.view.frame = CGRectMake(0, 30, self.view.frame.width, self.view.frame.height)
self.addChildViewController(self.pageViewController)
self.view.addSubview(self.pageViewController.view)
self.pageViewController.didMoveToParentViewController(self)
print("called")
}