所以我試圖從一組cloudkit下載的項目中創建一個tableview。但是,我有這個簡單的小「定義衝突與前值」的錯誤。這個錯誤發生在cellForRowAtIndexPath函數中,這個函數與numberOfRowsInSection函數衝突。我試圖移動/刪除後一個函數的括號,並在最後放置一個問號/可選項...「 - > UITableViewCell?」無濟於事。錯誤從哪裏來?定義與先前的值衝突 - 此外,何時被覆蓋刪除?
另外,xcode刪除了每個tableview函數的覆蓋部分。它爲什麼有時會停留,什麼時候被刪除?
import UIKit
import CloudKit
class DiningTable: UITableViewController {
var categories: Array<CKRecord> = []
override func viewDidLoad() {
super.viewDidLoad()
func getRecords()
{
categories = []
let publicDatabase = CKContainer.defaultContainer().publicCloudDatabase
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: "DiningTypes", predicate: predicate)
let queryOperation = CKQueryOperation(query: query)
queryOperation.desiredKeys = ["Name", "Address", "Picture"]
queryOperation.qualityOfService = .UserInteractive
queryOperation.recordFetchedBlock = { (record:CKRecord) -> Void in
let categoryRecord = record
self.categories.append(categoryRecord)
}
queryOperation.queryCompletionBlock = { (cursor:CKQueryCursor?, error: NSError?) -> Void in
if (error != nil) {
print("Failed to get data from iCloud - \(error!.localizedDescription)")
dispatch_async(dispatch_get_main_queue(), {
self.tableView.reloadData()
})
}
}
publicDatabase.addOperation(queryOperation
}
func tableView(tableView: UITableView, numberOfRowsInSection: Int) -> Int {
return self.categories.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("dining") as! DiningTableCell
let restaurant: CKRecord = categories[indexPath.row]
cell.RestaurantName?.text = restaurant.valueForKey("Name") as? String
let img = restaurant.objectForKey("Picture") as! CKAsset
cell.RestaurantPhoto.image = UIImage(contentsOfFile: img.fileURL.path!)
return cell
}
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "segue1" {
if let destViewController = segue.destinationViewController as? RestaurantTable {
let indexPath = self.tableView.indexPathForSelectedRow!
destViewController.indexpath1 = indexPath
}
}
}
func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
}
請包括代碼和錯誤信息作爲實際文本,不僅僅作爲屏幕截圖。 – luk2302
已更新。什麼時候屏幕截圖可以接受?代碼優先? –
代碼屏幕截圖幾乎不是一個好主意,因爲任何想要回答的人都會想要做的第一件事是複製並將你的代碼粘貼到Xcode中。 –