** 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, если это идентификатор или просто код, который я не слишком уверен, что он должен работать. Я клянусь, что он работал прошлой ночью, но сегодня он просто падает *
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!
}