well my problem is that idk how to pass the info values from the uitableviewcell to the anotherviewcontroller by the segue, could you please help, im unwraped the value, cause the data is already loaded idk what to do to pass the info to the popup controller without crashed
Here is my class model where i set the values
class MovieCell: UITableViewCell { // // MARK: - Class Constants // static let identifier = "MovieCell" let urlImage = "https://image.tmdb.org/t/p/w500" // // MARK: - IBOutlets // @IBOutlet weak var title: UILabel! @IBOutlet weak var rating: RatingView! @IBOutlet weak var releaseDate: UILabel! @IBOutlet weak var poster: UIImageView! var titlePopUp: String = "" func configure(movieDictionary: [String: Any]) { title.text = (movieDictionary["title"] as! String) titlePopUp = movieDictionary["title"] as! String releaseDate.text = (movieDictionary["release_date"] as! String) do { let url = URL(string: "\(self.urlImage)" + "\(movieDictionary["backdrop_path"]!)") let data = try Data(contentsOf: url!) self.poster!.image = UIImage(data: data) } catch{ print(error) } }
}
heres is the viewcontroller where i get the error in the line 53
import UIKit
class ViewController: UIViewController,UITableViewDataSource, UICollectionViewDataSource, UITableViewDelegate {
var jsonArray: [Any] = [] let movieService = MovieService() let popUpVC = popUpViewController() @IBOutlet weak var moviesTableView: UITableView! @IBOutlet weak var postersView: UICollectionView! override func viewDidLoad() { super.viewDidLoad() movieService.fetchMovies { jsonArray in if let jsonArray = jsonArray { self.jsonArray = jsonArray self.moviesTableView.reloadData() self.postersView.reloadData() } } self.moviesTableView.delegate = self self.moviesTableView.dataSource = self } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { self.jsonArray.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell:MovieCell = tableView.dequeueReusableCell(withIdentifier: "MovieCell", for: indexPath) as! MovieCell cell.configure(movieDictionary: jsonArray[indexPath.row] as! [String: Any]) return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { present(popUpVC, animated: true, completion: nil) moviesTableView.deselectRow(at: indexPath, animated: true) self.performSegue(withIdentifier: "popUp", sender: self) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "popUp" { let destinationVC = segue.destination as! popUpViewController let data = MovieCell() destinationVC.movieN = data.title.text! } }
and the popup controller is this one
class popUpViewController: UIViewController { @IBOutlet weak var poster: UIImageView! @IBOutlet weak var movieName: UILabel! @IBOutlet weak var releaseDate: UILabel! @IBOutlet weak var descriptionMovie: UILabel! var movieN = String() override func viewDidLoad() { super.viewDidLoad() movieName.text = movieN // Do any additional setup after loading the view. } @IBAction func closePop(_ sender: UIButton) { dismiss(animated: true, completion: nil) }
}
im getting crash passing the label and image, the clasical error, unexpected nil value, but idk why the data is already loaded in the tableview main screen
https://stackoverflow.com/questions/66847442/why-getting-unexpected-nil-value-passing-data-already-loaded-in-tableview-by-a-s March 29, 2021 at 08:30AM
没有评论:
发表评论