i am trying to create tableview that can change the data inside it depending on the brand clicked before, for example if i click on the Acura brand the tableview will then change the array into Acura array and when the car model in Acura is clicked it will show the car year. the problem with my code below is that, when the car brand model are clicked it chooses both the CARBRAND and the CARMODEL at the same time and it show the CAR YEAR. it seem the tableview just keep on selecting the row that i clicked
from here
then it keep click all the way to the car year
both car brand and car model already clicked at this point.

how do i stopped tableview from clicking twice. class jobtypeViewController: UIViewController,UITableViewDelegate,UITableViewDataSource { var thetitle = ""
// car make
var carbrand = ["Acura","Aston_Martin","AUDI","Bentley","BMW","Buick","Cadillac","Chevrolet","Dodge","FIAT","Ford","Genesis","GMC","Honda","Hyundai","Infinit","Jaguar","JEEP","KIA","Landrover","Lexus","Lincoln","Mazda","MercedezBenz","MINI","Mitsubishi","Nissan","Porsche","Scion","Subaru","Suzuki","Toyota","Volkswagen","Volvo"]
// car model
var Acura = ["ILX","MDX","NSX","RDX","RLX","RLX Sport Hybrid","TLX"]
// car year
var caryear = ["1998","1999","2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2011","2012","2013","2014","2015","2016","2017"]
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch thetitle {
case "Acura":
return Acura.count
case "brand":
return carbrand.count
case "model":
return Honda.count
case "year":
return caryear.count
default:
return 0
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
switch thetitle {
case "Acura":
cell.textLabel?.text = Acura[indexPath.row]
cell.textLabel?.textAlignment = .Center
case "brand":
cell.textLabel?.text = carbrand[indexPath.row]
cell.textLabel?.textAlignment = .Center
case "model":
cell.textLabel?.text = Honda[indexPath.row]
cell.textLabel?.textAlignment = .Center
case "year":
cell.textLabel?.text = caryear[indexPath.row]
cell.textLabel?.textAlignment = .Center
default:
cell.textLabel?.text = ""
}
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if thetitle == "automotive"{
switch carbrand[indexPath.row]{
case "Acura":
print(carbrand[indexPath.row])
tableviewz.hidden = true
thetitle = "Acura"
tableviewz.deselectRowAtIndexPath(tableviewz.indexPathForSelectedRow!, animated: true)
tableviewz.reloadData()
default:
print("hello")
}
}
if thetitle == "Acura"{
switch Acura[indexPath.row]{
case "ILX":
print(Acura[indexPath.row])
tableviewz.hidden = true
thetitle = "year"
tableviewz.reloadData()
tableviewz.hidden = false
default:
print("hello")
}
}
}
