0
我謂詞/查詢/ performquery代碼工作正常,我的表格單元格設置了正確的TableCell控制器和可重複使用的標識顯示,我已經抽象從我CKRecordType的valueForKey的nameLabel和有未能加載/查看更新UI。CloudKit應用數據未在tableview中
import UIKit
import CloudKit
class table: UITableViewController {
var categories: Array<CKRecord> = []
override func viewDidLoad() {
super.viewDidLoad()
}
func fetch()
{
categories = []
let publicDatabase = CKContainer.defaultContainer().publicCloudDatabase
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: "Dining", predicate: predicate)
publicDatabase.performQuery(query, inZoneWithID: nil) { (results, error) -> Void in
if (error != nil)
{
print("Error" + (error?.localizedDescription)!)
}
else
{
for result in results!
{
self.categories.append(result)
}
NSOperationQueue.mainQueue().addOperationWithBlock({() -> Void in
self.tableView.reloadData()
})
}
self.fetch()
}
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return self.categories.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("dining") as! tablecell
let restaurant: CKRecord = categories[indexPath.row]
cell.nameLabel.text = restaurant.valueForKey("Name") as? String
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
這裏,如果需要更多信息實際的項目:https://www.dropbox.com/sh/twt20r0sdauglhs/AAB6Y2CcxpT1hp0mBE_Znzgya?dl=0