以前にクリックしたブランドに応じてデータを変更できるtableviewを作成しようとしています。たとえば、Acuraブランドをクリックすると、アキュラの車のモデルをクリックすると車の年が表示されます。以下の私のコードの問題は、車のブランドモデルをクリックするとCARBRANDとCARMODELの両方を同時に選択し、CAR YEARを表示することです。それは車の年 両方の車のブランドと車のモデルが既にクリックされたにすべての方法をクリックしておくテーブルビューはちょうど私がUItableviewの可変データソースを作成する(viewcontrollerを使用)
ここから
どのようにしてtableviewが2回クリックされなくなったのですか? クラスjobtypeViewController:のUIViewController、UITableViewDelegate、UITableViewDataSource { するvar thetitle = "アキュラ" "あなたのdidSelectRowAtIndexPath
方法で
// 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")
}
}
}
私はコードをコピーして何とかacuraをクリックすると空白に戻ります。 – Alan
@Alanおそらく 'tableviewz.hidden = true'があるからです。 – pbasdf
あなたはあなたの命を救う権利を持っています。どうもありがとうございます – Alan