应用程序崩溃原因:'-[HOV1.itemShowViewController collectionView:numberOfItemsInSection:]: unrecognized select

Posted

技术标签:

【中文标题】应用程序崩溃原因:\'-[HOV1.itemShowViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x7fcc8f6a1320\'【英文标题】:App crashing reason: '-[HOV1.itemShowViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x7fcc8f6a1320'应用程序崩溃原因:'-[HOV1.itemShowViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x7fcc8f6a1320' 【发布时间】:2020-03-14 00:20:06 【问题描述】:
** it just crashes whenever I click the table to load the new view 
controller  reason: '-[HOV1.itemShowViewController collectionView:numberOfItemsInSection:]:
unrecognized selector sent to instance 0x7fcc8f6a1320'**

idk 如果它是一个标识符或只是代码我不太确定它应该工作我发誓它昨晚工作但今天它只是不断崩溃我尝试重新启动 Xcode 重建应用程序

import UIKit

 class ItemsTableViewController: UITableViewController 


var category : Category?

var itemArray : [Item] = []


override func viewDidLoad() 
    super.viewDidLoad()

    print("we have selected" , category?.name )


    self.title = category?.name



override func viewDidAppear(_ animated: Bool) 
    if category != nil 

        LoadItems()
    




    // MARK: - Table view data source

     /* override func numberOfSections(in tableView: UITableView) -> Int 
    // #warning Incomplete implementation, return the number of sections
    return 0
     */

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int         
    // #warning Incomplete implementation, return the number of rows
    return itemArray.count



override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->    UITableViewCell 
    let cell = tableView.dequeueReusableCell(withIdentifier: "addItemCell", for: indexPath)
        as! ITEMTableViewCell  //you need to specify which cell it needs to be talking too    so this one talks to item table view cell

    // Configure the cell...
    cell.generateCellForITEMS(item: itemArray[indexPath.row])

    return cell



//MARK: TABLEVIEW DELEGATE

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 

    tableView.deselectRow(at: indexPath, animated: true)

    //so when this the tables are tapped they will open up  a new view controller

    showItemsView(itemArray[indexPath.row]) //selects the item i want and passes it to the show item function





// 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?) 

   //gives u access to category function in add item viewcontroller
    if segue.identifier == "AddItemSegue" 

        let vc = segue.destination as! AddItemViewController
        vc.category = category!
    






private func showItemsView(_ _item : Item)

    //reason i have a if available code is because it gave me a problem about the version so using this code im able to check the version and use the approprate function the difference is the identfier one says "identifier" the other one says with "withidentifier"

    if #available(ios 13.0, *) 
        let itemVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(identifier: "itemVieww") as! itemShowViewController

         itemVC.item  = _item

         self.navigationController?.pushViewController(itemVC, animated: true)
    

    else 
        // Fallback on earlier versions
        let itemVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "itemVieww") as! itemShowViewController

        itemVC.item  = _item

         self.navigationController?.pushViewController(itemVC, animated: true)
    








   private func LoadItems()

  let item = Item()
item.downloadITEMSFromFirebase(withCategoryId: category!.id)  (allItems) in

    print("we have \(allItems.count) items for this category")
    self.itemArray = allItems
    self.tableView.reloadData()
  
 






idk 如果它是一个标识符或只是代码我不太确定它应该工作我发誓它昨晚工作但今天它只是不断崩溃我尝试重新启动 Xcode 重建应用程序

itemshowViewcontroller 的代码

import UIKit
import JGProgressHUD

 class itemShowViewController: UIViewController 


//MARK: VARS
var item : Item!
var itemImages : [UIImage] = []

let hud2 = JGProgressHUD(style: .dark)


//MARK: VIEW LIFECYCLE
   override func viewDidLoad() 
       super.viewDidLoad()

       // Do any additional setup after loading the view.

   // print("Item Name is", item.name)
   


//MARK: IBOUTLETS
@IBOutlet weak var imageCollectionView: UICollectionView!
@IBOutlet weak var priceLabel: UILabel!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var descriptionTextView: UITextView!





【问题讨论】:

添加itemShowViewController的代码 刚刚为它添加了代码 【参考方案1】:

当您在 storyborad/xib 中设置委托和数据源时,您没有在 itemShowViewController 内实现 numberOfItemsInSection && cellForItemAt

【讨论】:

以上是关于应用程序崩溃原因:'-[HOV1.itemShowViewController collectionView:numberOfItemsInSection:]: unrecognized select的主要内容,如果未能解决你的问题,请参考以下文章

Titanium - 确定应用程序崩溃的原因

如何找到并修复崩溃的原因

如何找到切换按钮崩溃的原因?

求助服务器崩溃原因和解决方法

服务器出现崩溃是啥原因呢?

Cordova 应用程序崩溃日志原因