Passing data into tableview

So i'm trying to pass data through multiple views but having a lot of bother. Essentially i'm trying to create a library/playlist in a table view

I have a table view where the user searches for movies (movie details from API ) and taps their selected movie which then segue to another view controller which displays more info on the users selection.

I'm then attempting to implement an 'add to library' button to then input this data into the table cell in a third view controller. The first segue (to movieDetailsVC) works perfectly however i'm having trouble sending data to the third view controller

I have assumed that in order to display this data in a table view it must first segue to the TableViewCell and then segue again to the final view controller?

MovieDetailVC (sends data to tableViewCell)

              override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
              let LibraryTableViewCell = segue.destination as! LibraryMovieTableViewCell
            LibraryTableViewCell.cellTitleLabel.text = movieTitle
            } 

TableViewCell(attempts to send data to final ViewController)

 `  **@IBOutlet** **weak** **var** cellTitleLabel: UILabel!`

**func** prepare(for segue: UIStoryboardSegue, sender: **Any** ?) {

**let** LibraryMovieViewcontroller = segue.destination **as** ! LibraryMovieViewController

LibraryMovieViewController.LibraryTitle.value = cellTitleLabel **as** ? String

}

LibraryViewController (attempts to display sent data in table)

**@IBOutlet** **weak** **var** tableView: UITableView!

**var** libraryMovies: [NSDictionary] = []


   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
     
        let libraryCell = tableView.dequeueReusableCell(withIdentifier: "libCell", for: indexPath) as! 
       LibraryMovieTableViewCell
        let libMovie = libraryMovies[indexPath.row]
        var libTitle = libMovie["title"] as! String
      
        libraryCell.cellTitleLabel.text = libTitle
        return libraryCell   
    }

This question is about the Apple frameworks, not the Swift language. You might have better luck over on the Apple developer forums, StackOverflow, or other on-line resources.

Terms of Service

Privacy Policy

Cookie Policy