I am trying to create a "simple" app that allows me to look up certain vehicles and gives me relevant information about it.
I have been following a video made by someone creating an app showing how to move info from one tableview to another, but despite my best efforts, I keep getting "Cannot invoke 'indexPathForSelectedRow' with no arguments" error for the following line:
var indexPath: NSIndexPath = self.tableView.indexPathForSelectedRow()!
The video is a couple of years old, so I believe the video maker may have an older version of Xcode and or Swift, but it seems so close?
The issue is in the first tableview controller file, I have included the second tableview controller file and tableview table in case either is causing the issue.
Can anyone tell me what is going wrong?
FIRST TABLEVIEW CONTROLLER:
import Foundation
import UIKit
class VehicleMakeController: UITableViewController {
var VehicleMakeArray = [String] ()
var VehicleModelArray = [VehicleModelTable] ()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
VehicleMakeArray = ["Ford", "Volkeswagon", "Peugeot"]
VehicleModelArray = [VehicleModelTable(SecondTitle: ["Mondeo", "Focus", "Fiesta"]), VehicleModelTable(SecondTitle: ["Caddy", "Golf", "Passat"]), VehicleModelTable(SecondTitle: ["Partner", "208", "106"])]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return VehicleMakeArray.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "VehicleMakeCell", for: indexPath) as UITableViewCell
// Configure the cell...
cell.textLabel?.text = VehicleMakeArray [indexPath.row]
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var indexPath: NSIndexPath = self.tableView.indexPathForSelectedRow()!
var DestViewController = segue.destination as! VehicleModelController
var VehicleModelArrayTwo: VehicleModelTable
VehicleModelArrayTwo = VehicleModelArray[indexPath.row]
DestViewController.VehicleModelArray = VehicleModelArrayTwo.SecondTitle
}
SECOND TABLEVIEW CONTROLLER:
import Foundation
import UIKit
class VehicleModelController: UITableViewController {
var VehicleModelArray = [String] ()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return VehicleModelArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let Cell = self.tableView.dequeueReusableCell(withIdentifier: "VehicleModelCell", for: indexPath as IndexPath) as UITableViewCell
// Configure the cell...
Cell.textLabel?.text = VehicleModelArray [indexPath.row]
return Cell
}
}
SECOND TABLEVIEW TABLE
import Foundation
struct VehicleModelTable {
var SecondTitle: [String]
}