Post

Replies

Boosts

Views

Activity

Reply to Need Help Transfer Data From Button
I have a custom cell actually. I have the function I used to display it at the bottom. I am curious with willRowAt do I return indexPath?    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()     }    } } }
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’21
Reply to Need Help Transfer Data From Button
Okay I get the same error unrecognized selector sent to instance '0x7fd4c4098200'. I tried both ways but end up with the same error. You don't but the button in the cell? override func prepare(for segue: UIStoryboardSegue, sender: Any?) {       if segue.identifier == "hs" {         if let destinationController = segue.destination as? HighlightsVC, let destName = selectedNameInCell {           destinationController.playerName = destName          }       }     }               override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {     if let cell = tableView.cellForRow(at: indexPath) as? FavCell {       selectedNameInCell = cell.name.text     }     return indexPath   }       @IBAction func CamButtonA(_ sender: UIButton) {     performSegue(withIdentifier: "hs", sender: nil)   }
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’21
Reply to Need Help Transfer Data From Button
Okay I have it working but it goes to the vc twice and it also does not transfer the name. override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {     if let cell = tableView.cellForRow(at: indexPath) as? FavCell {       selectedNameInCell = cell.name.text       print("destName is \(String(describing: selectedNameInCell))") //does not print name     }     return indexPath   }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Need Help Transfer Data From Button
Okay I will give you more detail I have a function that retrieves youtube data but it is called twice.    func fetchYoutubeData(completion: @escaping () -> ()) {           let API_Key = "key"           let theName = playerName     print("this is the player name that was transferred \(playerName)")           let query: [String: String] = ["part" : "snippet", "maxResults" : "5", "q" : theName + "nhl player highlights", "type" : "video", "key" : API_Key]           let baseURL = URL(string: "https://www.googleapis.com/youtube/v3/search")!     let url = baseURL.withQueries(query)!     print(url)           URLSession.shared.dataTask(with: url) { (data, response, error) in               guard let data = data else { return }               DispatchQueue.main.async {                             do {                                   let youtube = try JSONDecoder().decode(Highlights.self, from: data)           self.youtubeArr = youtube.items           self.tableView.reloadData()                                 } catch let jsonErr {           print("Error serializing json:", jsonErr)         }       }                     }.resume()        }
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 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 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 Delete Cells From A Set
Okay I will show you that I still have same issue.    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   }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Adding Restores Everything
You should show how you handle the passFavNotification (I mean, where do you call handleFavNotification)  I will show you where I called it's a detailed tableview controller where the button is to add favourites. extension Notification.Name {   static let passFavNotification = Notification.Name("pass") } class HockeyDetailVC: UITableViewController {    override func viewDidLoad() {     super.viewDidLoad()     gonnaLoadView()     tableV.bounces = false     tableV.alwaysBounceVertical = false     favButton.layer.cornerRadius = 10           // Add self as Observer and a function to handle it     NotificationCenter.default.addObserver(self,     selector: #selector(handleFavNotification(notification:)),     name: .passFavNotification,     object: nil)   }       @objc func handleFavNotification(notification:Notification){       if let theFav = notification.object as? CurrentPlayers {         self.item = theFav       }     } } Having two separate properties favArr and noRepFav may be causing the issue.  The thing is I need noRepFav because I don't want duplicates in my array.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Adding Restores Everything
I'm confused with this code: you have at least 2 different TableViewControllers (FavouritesVC, HockeyDetailVC). Both of them have handleFavNotification. It is not clear where you delete, where you add, where it is added back. The favourites I want to add is originally in hockeydetailvc where it is added by a button in that vc. I have an observer and notification function there. It is added to an array in FavouriteManager.swift. In my favouritesvc I use that array to hold my favourites and when a new favourites is added to favouritesvc it reloads the tableview with a notification. I can delete a favourite but when I add a new one it's as if the favourite I deleted comes back onto the array.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21