1

我有一个记录类型 - “DiningTypes”。“DiningTypes 只有一个字段类型,即字符串。我有 5 条记录……加载一张表需要 3-4 秒。这怎么这么慢?我需要在一个以前的控制器有更快的 UI 响应时间?

import UIKit
import CloudKit

class table1: UITableViewController {

var categories: Array<CKRecord> = []
var fetchedcategories: Array<CKRecord> = []

override func viewDidLoad() {
    super.viewDidLoad()
    func fetchdiningtypes()

    {
        let container = CKContainer.defaultContainer()
        let publicDatabase = container.publicCloudDatabase
        let predicate = NSPredicate(value: true)

        let query = CKQuery(recordType: "DiningTypes", 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)
                }

                              }
        }

    }
    fetchdiningtypes()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
 override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return categories.count
}
   override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("dining")     as! table1cell
    let restaurant: CKRecord = categories[indexPath.row]
    cell.Name.text = restaurant.valueForKey("Name") as? String

    return cell
}
}
4

1 回答 1

1

CloudKit 操作的默认服务质量是NSQualityOfServiceUtility. 如果您的应用程序在请求运行时不在前台,您可能会看到操作需要比平时更长的时间才能运行。

尝试使用CKQueryOperation并将其设置qualityOfServiceNSOperationQualityOfServiceUserInitiated.

于 2016-06-14T23:55:42.113 回答