実現したいこと
swiftのUITableVIewの表示・非表示をボタンで切り替えたい
発生している問題・分からないこと
下記のようにコードを書いているのですが、viewDidLoadで一度UITableViewを非表示にし、ボタンを押したところUITableVIewが再度表示されることはありませんでした。普通のviewの場合はこの記述で表示・非表示を切り替えることができたのですが、UITableViewだとなにか特殊なコードが必要になるのでしょうか?
viewDidLoadで非表示に設定することはできているので、ボタン押下で表示状態に戻したいです。
該当のソースコード
swift
1 2import UIKit 3 4class SampleViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 5 6 // プルダウン 7 @IBOutlet weak var inPull: UITableView! 8 9 override func viewDidLoad() { 10 super.viewDidLoad() 11 12 // プルダウン非表示 13 inPull.isHidden = true 14 15 } 16 17 18 let TODO = ["日本語","English","韓国語"] 19 20 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 21 return TODO.count 22 } 23 24 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 25 26 let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell",for: indexPath) 27 28 // セルの真ん中に表示 29 cell.textLabel!.textAlignment = .center 30 31 cell.textLabel!.text = TODO[indexPath.row] 32 return cell 33 } 34 35 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 36 return 20 37 } 38 39 @IBAction func pu(_ sender: Any) { 40 41 // プルダウンの中身を表示 42 inPull.isHidden = false 43 } 44 45}
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
viewもlabelも
該当View.ishidden = true or false で表示・非表示が可能と出てきました。
補足
xcodeを使用しています。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。