Ios Xcode can';找不到我的手机号码
我的代码有个错误,上面写着 “由于未捕获异常而终止应用程序 “NSInternalInconsistencyException”,原因:“无法将单元格出列。” 使用标识符ItemCell-必须为 标识符或连接故事板中的原型单元“?” 我已将单元格设置为Ios Xcode can';找不到我的手机号码,ios,swift,xcode,Ios,Swift,Xcode,我的代码有个错误,上面写着 “由于未捕获异常而终止应用程序 “NSInternalInconsistencyException”,原因:“无法将单元格出列。” 使用标识符ItemCell-必须为 标识符或连接故事板中的原型单元“?” 我已将单元格设置为ItemCell,并已运行Product>Clean。它仍然找不到它。有人能看出我做错了什么吗?我已经包括了我的代码和故事板的屏幕截图 import UIKit class ItemsViewController: UITableViewCon
ItemCell
,并已运行Product>Clean。它仍然找不到它。有人能看出我做错了什么吗?我已经包括了我的代码和故事板的屏幕截图
import UIKit
class ItemsViewController: UITableViewController {
var itemStore: ItemStore!
@IBAction func addNewItem(_ sender: UIButton) {
let newItem = itemStore.createItem()
if let index = itemStore.allItems.index(of: newItem) {
let indexPath = IndexPath(row: index, section: 0)
tableView.insertRows(at: [indexPath], with: .automatic)
}
}
@IBAction func toggleEditingMode(_ sender: UIButton) {
if isEditing {
sender.setTitle("Edit", for: .normal)
setEditing(false, animated: true)
} else {
sender.setTitle("Done", for: .normal)
setEditing(true, animated: true)
}
}
override func viewDidLoad() {
super.viewDidLoad()
let statusBarHeight = UIApplication.shared.statusBarFrame.height
let insets = UIEdgeInsetsMake(statusBarHeight, 0, 0, 0)
tableView.contentInset = insets
tableView.scrollIndicatorInsets = insets
tableView.rowHeight = 65
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return itemStore.allItems.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath) as! ItemCell
let item = itemStore.allItems[indexPath.row]
cell.nameLabel.text = item.name
cell.serialNumberLabel.text = item.serialNumber
cell.valueLabel.text = "$\(item.valueInDollars)"
return cell
}
override func tableView(_ tableView: UITableView,
commit editingStyle: UITableViewCellEditingStyle,
forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
let item = itemStore.allItems[indexPath.row]
let title = "Delete \(item.name)"
let message = "You sure ya wanna delete this?"
let ac = UIAlertController(title: title,
message: message,
preferredStyle: .actionSheet)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
ac.addAction(cancelAction)
let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: { (action) -> Void in
self.itemStore.removeItem(item)
self.tableView.deleteRows(at: [indexPath], with: .automatic)
})
ac.addAction(deleteAction)
present(ac, animated: true, completion: nil)
}
}
override func tableView(_ tableView: UITableView,
moveRowAt sourceIndexPath: IndexPath,
to destinationIndexPath: IndexPath) {
itemStore.moveItem(from: sourceIndexPath.row, to: destinationIndexPath.row)
}
这是我的手机
import UIKit
class ItemCell: UITableViewCell {
@IBOutlet var nameLabel: UILabel!
@IBOutlet var serialNumberLabel: UILabel!
@IBOutlet var valueLabel: UILabel!
}
还有我的物品商店
import UIKit
class ItemStore {
var allItems = [Item] ()
@discardableResult func createItem() -> Item {
let newItem = Item(random: true)
allItems.append(newItem)
return newItem
}
func removeItem(_ item: Item) {
if let index = allItems.index(of: item) {
allItems.remove(at: index)
}
}
func moveItem(from fromIndex: Int, to toIndex: Int) {
if fromIndex == toIndex {
return
}
let movedItem = allItems[fromIndex]
allItems.remove(at: fromIndex)
allItems.insert(movedItem, at: toIndex)
}
}
检查您是否在Identity Inspector中为单元格设置了正确的自定义类(
ItemCell
) 您必须在故事板中将自定义类名检查为ItemCell.swift
作为类名
故事板中原型单元的类类型是什么?1。您在哪里注册tableViewCell?2.在您的代码中搜索
注册
…您找到什么了吗?共享所有实例。只需尝试删除表视图层次结构下TableViewCell上方的UIView,或者将UITableViewController的类设置为该场景中的类?。我从其他控制器中添加了代码。谢谢你的帮助@蜂蜜原型单元由情节提要隐式注册。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// create a new cell if needed or reuse an old one
let cell:ItemCell = tableView.dequeueReusableCell(withIdentifier: "ItemCell") as! ItemCell
let item = itemStore.allItems[indexPath.row]
cell.nameLabel.text = item.name
cell.serialNumberLabel.text = item.serialNumber
cell.valueLabel.text = "$\(item.valueInDollars)"
return cell
}