swift - 定义与以前的值冲突 - 另外,何时删除覆盖?

标签 swift uitableview

所以我试图用一组 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.
}
}
}

最佳答案

你的整个类定义嵌套在你的

override func viewDidLoad() {

函数。在调用 super.viewDidLoad() 之后放置一个右括号

关于swift - 定义与以前的值冲突 - 另外,何时删除覆盖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37758344/

相关文章:

swift - 我可以有一个具有可变数量参数的通用枚举吗?

ios - 使用自定义选择颜色和边框创建分组的 UITableviewCell

ios - 在背景中为可重复使用的单元格加载文本内容

ios - Alamofire 接受和内容类型 JSON

ios - subview 将触摸传递给其下方的 subview

ios - 如果我在同一 View 上有两个 ImageView ,如何区分哪个 UIImagePickerController 调用 func didCancel?

iphone - 具有多个文本字段的组 TableView

ios - 无法在allowsMultipleSelection 上取消选择预选的uicollectionviewcells

iphone - 以编程方式计算包含 "<br>"或 "\n"的文本的 UITableViewCell 高度

ios - 如何找到图像的高度和宽度并适合具有宽高比的tableviewcell?