简体   繁体   English

将PFQuery的结果用作UIPageViewController的数据源

[英]Use results of PFQuery as DataSource for UIPageViewController

I'm trying to create a UIPageViewController that allows the user to scroll through full screen renderings of data, which is stored in a Parse Database. 我正在尝试创建一个UIPageViewController,该控件允许用户滚动显示存储在Parse数据库中的数据的全屏显示。

I started with XCode 6's page based application template, and have not changed anything in the DataViewController or the RootViewController. 我从XCode 6的基于页面的应用程序模板开始,并没有更改DataViewController或RootViewController中的任何内容。

In the initializer for the Model Controller, I added these lines of code: 在模型控制器的初始化程序中,我添加了以下代码行:

var pageData:NSArray = []

private func generateQuery() -> PFQuery? {
        let query = PFQuery(className:"Posts")
        query.orderByDescending("createdAt")
        return query
}
override init() {
        super.init()
        if let query = generateQuery(){
            query.findObjectsInBackgroundWithBlock(){
                (objects,error) in
                if error != nil{
                    println("ERROR")
                }
                else{
                   self.pageData = objects! as NSArray

                    }
                }

            }
    }

And when I compile and run I always get "found nil while unwrapping optional value" 当我编译并运行时,我总是得到“在解开可选值时发现nil”

I've tried a bunch of different permutations of NSArray, [AnyObject], [PFObject], etc. I assume it has something to do with making an asynchronous query in the initializer. 我已经尝试了许多不同的NSArray,[AnyObject],[PFObject]等排列。我认为它与在初始化程序中进行异步查询有关。 Is there any way to do this, or should I try something else? 有什么方法可以做,还是我应该尝试其他方法?

Maybe it's just a typo, but: 也许这只是一个错字,但是:

query.findObjectsInBackgroundWithBlock(){ ... }

Should be : 应该 :

query.findObjectsInBackgroundWithBlock({ ... })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM