My UITableViewController导致崩溃,错误消息如下:

由于未捕获的异常"NSInternalInconsistencyException"而终止应用程序,原因是:"无法将具有标识符单元格的单元格出列-必须为标识符注册nib或类,或在情节提要中连接原型单元格"

我知道我需要注册一个nib或一个类,但我不知道"在哪里或如何注册?".

import UIKit

class NotesListViewController: UITableViewController {

    @IBOutlet weak var menuButton: UIBarButtonItem!
    
  override func viewDidLoad() {
    super.viewDidLoad()
    NSNotificationCenter.defaultCenter().addObserver(self,
      selector: "preferredContentSizeChanged:",
      name: UIContentSizeCategoryDidChangeNotification,
      object: nil)
    
    // Side Menu
    
    if self.revealViewController() != nil {
        menuButton.target = self.revealViewController()
        menuButton.action = "revealToggle:"
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    }
    
  }

  override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    // whenever this view controller appears, reload the table. This allows it to reflect any changes
    // made whilst editing notes
    tableView.reloadData()
  }

  func preferredContentSizeChanged(notification: NSNotification) {
    tableView.reloadData()
  }

  // #pragma mark - Table view data source

  override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
  }

  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return notes.count
  }

  override func tableView(tableView: UITableView, cellForRowAtIndexPath   indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
    
    let note = notes[indexPath.row]
    let font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)
    let textColor = UIColor(red: 0.175, green: 0.458, blue: 0.831, alpha: 1)
    let attributes = [
      NSForegroundColorAttributeName : textColor,
      NSFontAttributeName : font,
      NSTextEffectAttributeName : NSTextEffectLetterpressStyle
    ]
    let attributedString = NSAttributedString(string: note.title, attributes: attributes)

    cell.textLabel?.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)

    cell.textLabel?.attributedText = attributedString
    
    return cell
  }

  let label: UILabel = {
    let temporaryLabel = UILabel(frame: CGRect(x: 0, y: 0, width: Int.max, height: Int.max))
    temporaryLabel.text = "test"
    return temporaryLabel
    }()

  override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    label.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)
    label.sizeToFit()
    return label.frame.height * 1.7
  }

  override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
      notes.removeAtIndex(indexPath.row)
      tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    }
  }

  // #pragma mark - Navigation

  // In a storyboard-based application, you will often want to do a little preparation before navigation
  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if let editorVC = segue.destinationViewController as? NoteEditorViewController {

      if "CellSelected" == segue.identifier {
        if let path = tableView.indexPathForSelectedRow() {
          editorVC.note = notes[path.row]
        }
      } else if "AddNewNote" == segue.identifier {
        let note = Note(text: " ")
        editorVC.note = note
        notes.append(note)
      }
    }
  }

}

推荐答案

您是否在故事板中将Table Cell标识符设置为"Cell"?

或者你有没有在那个场景中把UITableViewController的班级设为你的班级?

Ios相关问答推荐

OSLog(Logger)通过简单的字符串插值给出错误

在SwiftUI中动态隐藏列表的空部分

带有RadStudio 11.3/12的Mac Mini M2(Sonoma 14.2.1)上的PAServer-测试连接按钮有效,但部署不起作用

将数据传回VC时委托为空

Xcode -Google Mobile Ads SDK在没有AppMeasurement的情况下初始化

如何防止UITest套件与Fastlane一起执行?

OBJC @selector 在另一个实现中不起作用

拔下设备后,DriverKit USB 驱动程序 (dext) 进程不会终止

渲染的海边重定向在物理 iOS 设备上不起作用

从视图模型中更新 EnvironmentObject

在 iPad 上删除列表的顶部和底部行

如何将标准化坐标系中的点的位置转换为具有相对位置的常规坐标系?

iOS:应用程序在安装应用程序时未征求用户许可.每次都获得 kCLAuthorizationStatusNotDetermined - Objective-c & Swift

通过touch 传递到下面的 UIViews

Xcode 4.1 致命错误:自构建预编译头文件后修改了 stdlib

如何从一个特定的视图控制器中隐藏导航栏

将 iPhone xib 转换为 iPad xib?

AFNetworking 2.0 向 GET 请求添加标头

打开 XIB 文件后 Xcode 6.3 冻结/挂起

你如何以编程方式从视图控制器中画一条线?