So, im trying to pass data from one view controller into a tableview on a second view controller
However when I try to set the destination in the prepare segue function of the first view controller I receive an error: Value of type 'LibraryMovieViewController' has no member 'lib movie'
Initial View controller (attempts to send movieTitle to second view controller)
var movieTitle: String!
var movieReleaseDate: String!
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let DestViewController: LibraryMovieViewController = segue.destination as! LibraryMovieViewController
DestViewController.libMovie.title = movieTitle
DestViewController.libMovie.release = movieReleaseDate
}
LibraryMovievieController
struct libMovie {
//let mainImage: UIImage
let title: String
let release: String
}
class LibraryMovieViewController: UIViewController {
@IBOutlet weak var TableView: UITableView!
var dataSource: [libMovie] = []
var movieTitle: String!
var movieRelease: String!
func loadDataSource(){
dataSource.append(libMovie(title: " \(String(describing: movieTitle))", release: " \(String(describing: movieRelease))"))
tableView.reloadData()
}
extension LibraryMovieViewController: UITableViewDataSource, UITableViewDelegate{
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 115
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSource.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let movieCell = tableView.dequeueReusableCell(withIdentifier: "libCell", for: indexPath) as? LibraryMovieTableViewCell else {
return UITableViewCell()
}
let libMovie = dataSource[indexPath.row]
movieCell.cellTitleLabel.text = "Movie Title:\(libMovie.title)"
movieCell.cellReleaseLabel.text = "Release Date:\(libMovie.release)"
return movieCell
}
I have tried sending the data to the variables movieTitle and movieRelease and setting NumberOfRowsInSection to 1 but this returns nil
I receive an error: Value of type View Controller has no member libMovie
DestViewController.libMovie.title = movieTitle
DestViewcontorller.datasource also produces and error -> Cannot assign value of type 'String?' to type '[libMovie]'