在我的 TableViewController 中我有这行代码
override func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
在这个 block 中我尝试获取对象列表
let list = frc.objectAtIndexPath(indexPath) as! List
但我收到这个警告:
Use of undeclared type "List"
有人知道怎么处理吗?
这是完整的代码:
var frc: NSFetchedResultsController = NSFetchedResultsController()
override func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell",
forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
let list = frc.objectAtIndexPath(indexPath) as! list
cell.textLabel?.text = list.name
cell.detailTextLabel?.text = list.url
return cell
}
欢迎任何帮助!!
问候和感谢
最佳答案
在本教程中,Jason 在其数据模型文件中创建了一个名为“List”的实体,然后创建了一个名为 List 的类。
以下链接在他创建此文件后立即开始播放视频。
https://youtu.be/GeM7Zw12wbM?t=5m30s
您可能以不同的方式命名您的实体。
我将我的记录命名为记录,因为我正在存储记录。
所以我的代码如下所示:
var frc: NSFetchedResultsController = NSFetchedResultsController()
override func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell",
forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
// ALL occurrences of "list" are instead "record"
// ALL occurrences of "List" are instead "Record"
let record = frc.objectAtIndexPath(indexPath) as! Record
cell.textLabel?.text = record.name
cell.detailTextLabel?.text = record.url
return cell
}
关于xcode - Swift 1.2 - 列表类型未声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31479327/