Swift 3 tableviews with detailVC

我正在练习结构和表格,直到被卡住才很有趣。 我在第一个tableview(奥迪,宝马,梅赛德斯,欧宝)有4家汽车公司,然后点击一家汽车公司,我得到多年选择,2015年,2014年等等,每年应该有一套不同的汽车(制造在那一年),但我每年都得到相同的汽车(audi1,audi2,audi3,audi4),当点击不同的公司时,每个公司都有不同的年份,这是有效的。 那么,在哪里放置arrays以及2014年如何展示audi5,audi6,audi7,AUDI8。 当点击汽车时,它应该显示该汽车的详细文本和图像,这一切都在没有tableview的情况下工作多年,我设法用2个tableviews with detailvc,但现在尝试额外的tableview,(年)并得到卡住。

FirstTableViewcontroller

Import UIKit class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var tableView: UITableView! var firstArray = [String]() var secondArray = [FirstStruct]() var thirdArray = [SecondStruct]() override func viewDidLoad() { super.viewDidLoad() self.tableView.delegate = self self.tableView.dataSource = self firstArray = ["Audi", "Bmw", "Mercedes", "Opel"] secondArray = [FirstStruct(secondTitle: ["2015", "2014"]), FirstStruct(secondTitle: ["2015", "2014"]), FirstStruct(secondTitle: ["2015", "2014"]), FirstStruct(secondTitle: ["2015", "2014"])] thirdArray = [SecondStruct(thirdTitle: ["Audi 1", "Audi 2", "Audi 3", "Audi 4"]), SecondStruct(thirdTitle: ["Bmw1", "Bmw2", "Bmw3", "Bmw4"]), SecondStruct(thirdTitle: ["Mercedes1", "Mercedes2", "Mercedes3", "Mercedes4"]), SecondStruct(thirdTitle: ["Opel 1", "Opel 2", "Opel 3", "Opel 4"])] } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return firstArray.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell cell.textLabel?.text = firstArray[indexPath.row] return cell } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let indexPath : NSIndexPath = self.tableView.indexPathForSelectedRow! let destVC = segue.destinationViewController as! SecondTableViewController let join : FirstStruct join = secondArray[indexPath.row] destVC.firstArray = join.secondTitle let join2 : SecondStruct join2 = thirdArray[indexPath.row] destVC.secondArray = join2.thirdTitle } } 

Secondtableviewcontroller

 import UIKit class SecondTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var tableView: UITableView! var firstArray = [String]() var secondArray = [String]() override func viewDidLoad() { super.viewDidLoad() self.tableView.delegate = self self.tableView.dataSource = self } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return firstArray.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell cell.textLabel?.text = firstArray[indexPath.row] return cell } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { //let indexPath : NSIndexPath = self.tableView.indexPathForSelectedRow! let destVC = segue.destinationViewController as! ThirdTableViewController //let divide = secondArray[indexPath.row] destVC.firstArray = secondArray } } } 

ThirdTableViewController

 import UIKit class ThirdTableViewController: UIViewController,UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var tableView: UITableView! var firstArray = [String]() override func viewDidLoad() { super.viewDidLoad() self.tableView.delegate = self self.tableView.dataSource = self } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return firstArray.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell cell.textLabel?.text = firstArray[indexPath.row] return cell } }