搜索解决方案后,我无法解决此问题, 我有这段代码来列出核心数据中的数据:
import UIKit
import CoreData
class ViewControllerClass: UITableViewController, NSFetchedResultsControllerDelegate{
let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
var fetchedResultController: NSFetchedResultsController = NSFetchedResultsController()
var intermedioLat:String = ""
var intermedioLong:String = ""
@IBOutlet weak var listagem: UITableView!
var velocidade = ["40","50","70","90","100","120"]
func textFieldSouldReturn (textField: UITextField) -> Bool{
textField.resignFirstResponder()
return true
}
override func viewDidLoad() {
print(intermedioLat)
print(intermedioLong)
fetchedResultController = getFetchedResultController()
fetchedResultController.delegate = self
fetchedResultController.performFetch(nil)
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func getFetchedResultController() -> NSFetchedResultsController {
fetchedResultController = NSFetchedResultsController(fetchRequest: taskFetchRequest(), managedObjectContext: managedObjectContext!, sectionNameKeyPath: nil, cacheName: nil)
return fetchedResultController
}
func taskFetchRequest() -> NSFetchRequest {
let fetchRequest = NSFetchRequest(entityName: "Radar")
let sortDescriptor = NSSortDescriptor(key: "descricao", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]
return fetchRequest
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
let numberOfSections = fetchedResultController.sections?.count
return numberOfSections!
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let numberOfRowsInSection = fetchedResultController.sections?[section].numberOfObjects
return numberOfRowsInSection!
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Celula", forIndexPath: indexPath) as! UITableViewCell
let task = fetchedResultController.objectAtIndexPath(indexPath) as! Radar
cell.textLabel?.text = task.descricao
return cell
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
let managedObject:NSManagedObject = fetchedResultController.objectAtIndexPath(indexPath) as! NSManagedObject
managedObjectContext?.deleteObject(managedObject)
managedObjectContext?.save(nil)
}
func controllerDidChangeContent(controller: NSFetchedResultsController) {
tableView.reloadData()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "fromEventTableToAddEvent"{
var enviaInterLat : adicionarRadar = segue.destinationViewController as! adicionarRadar
enviaInterLat.latitude = intermedioLat
var enviaInterLong : adicionarRadar = segue.destinationViewController as! adicionarRadar
enviaInterLong.longitude = intermedioLong
}}
}
我有这样的错误:
由于未捕获的异常而终止应用 ' NSInternalInconsistencyException',原因:' - [UITableViewController loadView]加载了" TuG-ju-H3E-view-l3X-mv-HmR"笔尖,但没有得到 UITableView的' ***第一次抛出调用堆栈:libc ++ abi.dylib:以NSException类型的未捕获异常终止
我不知道还有什么要做,因为我尝试了一切
答案 0 :(得分:1)
您将类声明为UITableViewController
,在这种情况下,视口需要连接到表格视图。但是,如果您想要一个包含UITableView
的视图,那么简单地使控制器成为符合UIViewController
和UITableViewDelegate
协议的UITableViewDataSource
,这将会消失。
将其更改为
class ViewControllerClass: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate