我有一个错误,idk如何解决它。错误是:“定义与先前值冲突。”我复制了下面的代码,并标记了标记的部分。 提前谢谢。
import UIKit
import Parse
class ScienceTableViewController: UITableViewController, UITableViewDataSource {
var dataRecords = [Data]()
override func viewDidLoad() {
super.viewDidLoad()
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
dataRecords = [Data]()
let query = PFQuery(className: "data")
query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
for object in objects! {
let data = Data(objectID: object.valueForKey("objectId")! as! String, title: object.valueForKey("title")! as! String, date: object.valueForKey("date")! as! String, information: object.valueForKey("information")! as! String)
self.dataRecords.append(data)
self.tableView.reloadData()
}
} else {
print(error)
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return dataRecords.count > 0 ? 1 : 0
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataRecords.count
}
**override func tableView(tableView: UITableView**, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
// Configure the cell...
let title = dataRecords[indexPath.row].title
let date = dataRecords[indexPath.row].date
let information = dataRecords[indexPath.row].information
cell.textLabel?.text = title
cell.detailTextLabel?.text = date
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let controller: ViewController = segue.destinationViewController as! ViewController
if segue.identifier == "newData" {
controller.objectID = ""
} else if segue.identifier == "showData" {
let indexPath: NSIndexPath = self.tableView.indexPathForSelectedRow!
controller.objectID = dataRecords[indexPath.row].objectID
}
}
}}
我也遇到了xCode的问题,它声称“Xcode遇到问题。源编辑器功能有限。尝试恢复”,编辑器无法识别代码的短暂时间。
答案 0 :(得分:0)
我相信您的问题在于具有UITableViewDataSource作为协议的类声明行。 UiTableViewController已经是一个数据源,因此是多余的,应该删除。