简体   繁体   中英

UITableViewController: NSInternalInconsistencyException

After searching for solution I cant resolve this issue, I have this code to list the data from core data:

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
        }}
}

and I have a error like this:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "TuG-ju-H3E-view-l3X-mv-HmR" nib but didn't get a UITableView.' *** First throw call stack: libc++abi.dylib: terminating with uncaught exception of type NSException

I dont know what more to do because I try everything

You declare your class as a UITableViewController in this case the view outlet must be connected to the table view. However if you want a view that contains a UITableView then simple make the controller a UIViewController which conforms to the UITableViewDelegate and UITableViewDataSource protocols and this will go away.

Change it to

class ViewControllerClass: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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