gpt4 book ai didi

ios - UITableViewController : NSInternalInconsistencyException

转载 作者:行者123 更新时间:2023-11-29 02:00:04 24 4
gpt4 key购买 nike

在搜索解决方案后我无法解决这个问题,我有这段代码来列出核心数据中的数据:

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

我有一个这样的错误:

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

我不知道还能做什么,因为我尝试了一切

最佳答案

您将您的类声明为 UITableViewController,在这种情况下, View 导出必须连接到 TableView 。但是,如果您想要一个包含 UITableView 的 View ,那么简单地将 Controller 设为 UIViewController,它符合 UITableViewDelegateUITableViewDataSource 协议(protocol),这将消失。

改成

class ViewControllerClass: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate

关于ios - UITableViewController : NSInternalInconsistencyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30471229/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com