2
我試圖執行以下操作,但是當我將內容添加到表中時,它會崩潰。與此錯誤:'NSInternalInconsistencyException',原因:'無法使用標識符出列單元格
「NSInternalInconsistencyException」,原因:「無法出列具有標識符UtilityTableViewCell細胞 - 必須註冊標識符的筆尖或一類或連接在一個情節串連圖板的原型細胞」
import UIKit
class UtilityBillTableViewController: UITableViewController {
var bills = [UtilityBill]()
override func viewDidLoad() {
super.viewDidLoad()
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return bills.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "UtilityTableViewCell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! UtilityTableViewCell
let bill = bills[indexPath.row]
cell.billName.text = bill.billName
cell.totalDue.text = bill.amountDue
cell.totalDue.text = bill.dueDate
return cell
}
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
}
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
@IBAction func unwindToBillList(sender: UIStoryboardSegue){
if let sourceViewController = sender.source as? UtilitiesViewController, let bill = sourceViewController.bill {
// Add a new meal item.
let newIndexPath = NSIndexPath(row: bills.count, section: 0)
bills.append(bill)
tableView.insertRows(at: [newIndexPath as IndexPath], with: .bottom)
}
}
}
謝謝你的線索!!!!!! cellIdentifier vimerable不匹配屬性檢查器中標識符的實際名稱 –