Post

Replies

Boosts

Views

Activity

Reply to Delete Cells From A Set
Okay I have another error with deleting: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Need Help Transfer Data From Button
Okay I can give you the favcell code it's a custom cell, the segue to HighlightsVC is put where the button is. class FavCell: UITableViewCell {       let imageController = FetchImage()           @IBOutlet weak var favImg: UIImageView!       @IBOutlet weak var name: UILabel!       @IBOutlet weak var team: UILabel!       @IBOutlet weak var position: UILabel!           @IBOutlet weak var highlights: UIButton!           @IBOutlet weak var stats: UIButton!           func update(with itemFav: CurrentPlayers) {     name.text = itemFav.yahooName     team.text = itemFav.team     position.text = itemFav.position     favImg.image = UIImage(named: "Grey")     let url = URL(string: itemFav.photoUrl!)     imageController.fetchItemArtwork(url: url!) {       (image) in       if let image = image {         DispatchQueue.main.async {           self.favImg.image = image           self.favImg.roundedImage()         }   } }   }           func goToSite() {     if let url = URL(string: "https://www.hockey-reference.com/") {     UIApplication.shared.open(url, options: [:])   }   }                 }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Need Help Transfer Data From Button
Okay I will show the complete code. The error I am getting is the name being transferred is nil. The willSelectRowAt is does not extend the scope of the selectedNameInCell. class FavouritesVC: UITableViewController {       var currentFav: CurrentPlayers?           var selectedNameInCell : String?       var favSet: OrderedSet<CurrentPlayers> {     FavouriteManager.shared.favSet   }       override func viewDidLoad() {     super.viewDidLoad()     if currentFav == nil {     //display nil     self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none     } else {     NotificationCenter.default.post(name: .passFavNotification,     object: self.currentFav)     }   }       @objc     func handleFavNotification(notification: Notification) {       tableView.reloadData()     }       override func numberOfSections(in tableView: UITableView) -> Int {      return 1   }   override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {     return favSet.count   }           override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {     return 152   }           override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {     let cell = tableView.dequeueReusableCell(withIdentifier: "favcell", for: indexPath) as! FavCell     let itemFav = favSet[favSet.index(favSet.startIndex, offsetBy: indexPath.row)]     cell.layer.borderColor = UIColor.black.cgColor     cell.layer.borderWidth = 0.5     cell.contentView.backgroundColor = .random     cell.update(with: itemFav)     return cell   }       override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {     if let cell = tableView.cellForRow(at: indexPath) as? FavCell {       selectedNameInCell = cell.name.text     }     return indexPath   }               override func prepare(for segue: UIStoryboardSegue, sender: Any?) {       if segue.identifier == "hs" {         print("this is the segue destination: \(segue.destination)")         print("name being transferred is \(selectedNameInCell)")         if let destinationController = segue.destination as? HighlightsVC, let destName = selectedNameInCell {           destinationController.playerName = destName          }       }     }     }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Delete Cells From A Set
Okay I have another error with deleting: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Delete Cells From A Set
Okay I guess I can turn it into an array it would make it so much simpler. I really don't understand how to set it.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Need Help Transfer Data From Button
Okay I can give you the favcell code it's a custom cell, the segue to HighlightsVC is put where the button is. class FavCell: UITableViewCell {       let imageController = FetchImage()           @IBOutlet weak var favImg: UIImageView!       @IBOutlet weak var name: UILabel!       @IBOutlet weak var team: UILabel!       @IBOutlet weak var position: UILabel!           @IBOutlet weak var highlights: UIButton!           @IBOutlet weak var stats: UIButton!           func update(with itemFav: CurrentPlayers) {     name.text = itemFav.yahooName     team.text = itemFav.team     position.text = itemFav.position     favImg.image = UIImage(named: "Grey")     let url = URL(string: itemFav.photoUrl!)     imageController.fetchItemArtwork(url: url!) {       (image) in       if let image = image {         DispatchQueue.main.async {           self.favImg.image = image           self.favImg.roundedImage()         }   } }   }           func goToSite() {     if let url = URL(string: "https://www.hockey-reference.com/") {     UIApplication.shared.open(url, options: [:])   }   }                 }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Need Help Transfer Data From Button
Okay I will show the complete code. The error I am getting is the name being transferred is nil. The willSelectRowAt is does not extend the scope of the selectedNameInCell. class FavouritesVC: UITableViewController {       var currentFav: CurrentPlayers?           var selectedNameInCell : String?       var favSet: OrderedSet<CurrentPlayers> {     FavouriteManager.shared.favSet   }       override func viewDidLoad() {     super.viewDidLoad()     if currentFav == nil {     //display nil     self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none     } else {     NotificationCenter.default.post(name: .passFavNotification,     object: self.currentFav)     }   }       @objc     func handleFavNotification(notification: Notification) {       tableView.reloadData()     }       override func numberOfSections(in tableView: UITableView) -> Int {      return 1   }   override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {     return favSet.count   }           override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {     return 152   }           override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {     let cell = tableView.dequeueReusableCell(withIdentifier: "favcell", for: indexPath) as! FavCell     let itemFav = favSet[favSet.index(favSet.startIndex, offsetBy: indexPath.row)]     cell.layer.borderColor = UIColor.black.cgColor     cell.layer.borderWidth = 0.5     cell.contentView.backgroundColor = .random     cell.update(with: itemFav)     return cell   }       override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {     if let cell = tableView.cellForRow(at: indexPath) as? FavCell {       selectedNameInCell = cell.name.text     }     return indexPath   }               override func prepare(for segue: UIStoryboardSegue, sender: Any?) {       if segue.identifier == "hs" {         print("this is the segue destination: \(segue.destination)")         print("name being transferred is \(selectedNameInCell)")         if let destinationController = segue.destination as? HighlightsVC, let destName = selectedNameInCell {           destinationController.playerName = destName          }       }     }     }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Need Help Transfer Data From Button
I analyzed it and there's 2 segues that are going to the VC. So that's why it's being called twice. I have to get rid of the button action and do a segue with storyboard.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21