簡體   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