【问题标题】:Xcode 7 - Swift - Use of undeclared type 'UITableviewcell' [closed]Xcode 7 - Swift - 使用未声明的类型'UITableviewcell' [关闭]
【发布时间】:2016-09-06 15:55:43
【问题描述】:

错误是错别字,请删除

我只是 swift 的新手,这可能只是一个非常基本的问题。 如果有人可以提供帮助,那就太好了。

我正在关注关于如何在 swift/xcode 中制作滑出菜单的 youtube 教程,但出现了这个错误。我已经仔细检查过,并且编写了与教程中完全相同的代码。我已经研究并尝试修复它,但不能。

我知道错误是:

as UITableViewCell

在最后 5 行代码的末尾。但我不知道为什么,教程说要包括它。请帮忙。

import Foundation
import UIKit

class backTableViewController: UITableViewController {

  var TableArray = [String]()

  override func viewDidLoad() {
    TableArray = ["Hello", "Second", "World"]
  }

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

  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableviewCell

    return cell
  }
}

【问题讨论】:

  • 错字:UITableviewCell != UITableViewCell
  • 那么错误是什么?
  • 你的手机注册了吗?
  • 任何一个错字,但我不这么认为,因为那样会产生编译错误。我猜 cellIdentifier 在情节提要上没有正确设置。请在您的故事板中检查 uitableviewcell 的标识符
  • @MihribanMinaz 有一个编译错误,它在问题的标题中:“使用未声明的类型'UITableviewcell'”。您可以在 OP 的代码中看到确实是错字。

标签: ios xcode swift uitableview types


【解决方案1】:

在您的代码 sn-p 中,您有一个错字。

这一行

var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableviewCell

应该是

var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell

当您对UITableViewCell (as UITableViewCell) 进行强制转换时使用大写 V

希望这就是导致您的问题的原因

【讨论】:

  • 请避免发布“错字”问题的答案。这些问题只对OP有用,对其他用户没有帮助,最终会被关闭并删除。最好只发表评论并标记/投票结束。谢谢。 :)
  • 我明白你的观点@EricD,生活和学习嗯:)
  • 感谢您的回答,已解决:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-20
相关资源
最近更新 更多