使用PFQueryTableViewController(来自parse)和Swift [英] Use PFQueryTableViewController (from parse) with Swift
问题描述
我在故事板中添加了一个UITableViewController,并创建/分配了一个新类,它继承自PFQueryTableViewController到storyboard控制器。然后我编写了以下init函数,但我无法让Table视图控制器正常工作。
I have added a UITableViewController to storyboard and created/assigned a new class which inherits from PFQueryTableViewController to the storyboard controller. I then wrote the following init functions but I am unable to get the Table view controller working correctly.
为了实例化PFQueryTableViewController需要实现什么?
Parse doc中的代码在swift中无法正常工作。
What needs to be implemented in order to instantiate the PFQueryTableViewController? The code in the Parse doc is not working correctly in swift.
init(coder aDecoder: NSCoder!){
super.init(coder: aDecoder)
}
init(className aClassName: String!) {
super.init(className: aClassName)
self.parseClassName = "Timeline"
self.textKey = "Name"
self.pullToRefreshEnabled = true
self.paginationEnabled = false
}
推荐答案
您需要初始化ViewController。作为测试,在你的appdelegate中初始化它,如下所示:
You need to initialize the ViewController. As a test, initialize it in your appdelegate like this:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.setApplicationId("YOUR_APP_ID", clientKey:"YOUR_CLIENT_KEY")
var controller:PFQueryTableViewController = PFQueryTableViewController(className: "YOUR_PARSE_CLASS_NAME")
self.window?.rootViewController = controller
return true
}
这是我的PFQUeryTableViewController
Here is my PFQUeryTableViewController
class TestTableViewController: PFQueryTableViewController {
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(className aClassName: String!) {
super.init(className: aClassName)
self.parseClassName = aClassName
self.textKey = "YOUR_PARSE_COLOMN_YOU_WANT_TO_SHOW"
self.pullToRefreshEnabled = true
self.paginationEnabled = false
}
}
希望这有帮助,如果您有任何疑问,请与我联系。注意,我们需要在此类的初始值设定项中传入类名。我们在这里的appdelegate中传递了这个类名,但是当我们将这个视图添加到另一个控制器时,我们会在那里传递类名。这更能让你起步并运行
Hope this helps, let me know if you have any questions. Note, we need to pass in a class name in the initializer for this class. We pass that class name in the appdelegate here, but when we add this view to another controller, we would pass in the class name there instead. This was more to get you up and running
这篇关于使用PFQueryTableViewController(来自parse)和Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!