繁体   English   中英

UITableViewController:NSInternalInconsistencyException

[英]UITableViewController: NSInternalInconsistencyException

搜索解决方案后,我无法解决此问题,我得到了以下代码以列出核心数据中的数据:

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类型的未捕获异常终止

我不知道该怎么办,因为我尝试了一切

您将您的类声明为UITableViewController在这种情况下,视图出口必须连接到表格视图。 但是,如果您想要一个包含UITableView的视图,则只需简单地使控制器成为符合UITableViewDelegateUITableViewDataSource协议的UIViewController即可。

更改为

class ViewControllerClass: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM