i am trying to call an array from my viewcontroller and then setting text from that array which contains objects. But when i perform the segue it only gives me an "Index out of range" I do not see what i have done wrong. I have also tried to use the self. everywhere in the call but it dosent seem to be the problem.
The variable movie is where i try to get only 1 movie from the array but the same problem persists. Have I done something wrong with my viewcontroller or do i need to pass a value in?
Detailsviewcontroller is the controller for the new view and the tableview, that is why i have created another class inside the file.
File: DetailsviewController
import UIKit
class DetailsViewController: UIViewController, UITableViewDataSource,UITabBarDelegate {
@IBOutlet weak var tableView: UITableView!
var mainController = ViewController()
var movie = ViewController().self.movieArray[0]
var titles = ["Title", "Release Date","Genres","OverView"]
override func viewDidLoad() {
super.viewDidLoad()
print(movie)
// Do any additional setup after loading the view.
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return titles.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! DetailsCustomcell
cell.detailTitle.text = titles[indexPath.row]
if indexPath.row == 0{
cell.detailContent.text = ""
}
if indexPath.row == 1{
cell.detailContent.text = ""
}
if indexPath.row == 2{
cell.detailContent.text = "Movie genre´s is not fixed yet"
}
if indexPath.row == 3{
cell.detailContent.text = ""
}
return cell
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
class DetailsCustomcell: UITableViewCell{
@IBOutlet weak var detailTitle: UILabel!
@IBOutlet weak var detailContent: UILabel!
}