当前位置: 首页 > 面试题库 >

无法使带有标识符Cell的单元出队-必须为该标识符注册一个笔尖或一个类或在情节提要中连接原型单元

柳宾实
2023-03-14
问题内容

对于一般的编码我还是很陌生,对Xcode(Swift)真的很陌生。我知道我需要注册一个笔尖或一个类,但我不理解“在哪里或如何?”。

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

}

问题答案:

您是否在情节提要中将 表格单元格 标识符设置为“单元格”?

还是您将的课程设置UITableViewController为该场景中的课程?



 类似资料:
  • 我已经升级到Xcode 7,突然我的一个目标无法使用“宏名称必须是标识符”消息构建。此目标的调试配置构建正常,我可以在设备上运行它,但发布配置不会构建。 错误指向目标的.pch文件,但对于许多其他目标(包括已发布的目标),相同的.pch文件构建正常。 以下是错误消息: 这是。pch文件: 我已经尝试过清理和Xcode重启。 我将非常感谢任何关于如何深入挖掘并找到问题所在的建议。

  • 我正在使用SODA for Java存储和检索Oracle12c DB中的文档。我正在效仿这个例子。 这一例外背后的原因将是什么?

  • 我现在收到的每一条消息都会出现以下错误: 1437425804:未注册标识符为“未找到默认值”的图标 仅当后端用户登录时,才会发生此错误。对于刚刚访问网站(没有后端用户登录会话)的用户来说,网站工作正常。 我不知道有一个带有标识符的图标,也不知道从哪里开始调试。扩展扫描仪看起来不错。有人给我一个提示吗? 编辑 这是错误的回溯: Fri,19 Mar2021 12:28:52 0100[关键]请求=

  • 所以我一直有这个错误,我不知道发生了什么。我在谷歌上搜索了一下,读了一些关于这个错误的问题,但什么都没用。我只想运行它,这样我就可以完成我的项目。 错误:开始低库存;结束;*第1行错误:ORA-06550:第1行,第9列:PLS-00201:标识符“LOWINVENTORY”必须声明ORA-06550:第1行,第7列:PL/SQL:忽略语句 编辑: 表创建: