swiftのUITableVIewの表示・非表示をボタンで切り替えたい

実現したいこと

swiftのUITableVIewの表示・非表示をボタンで切り替えたい

発生している問題・分からないこと

下記のようにコードを書いているのですが、viewDidLoadで一度UITableViewを非表示にし、ボタンを押したところUITableVIewが再度表示されることはありませんでした。普通のviewの場合はこの記述で表示・非表示を切り替えることができたのですが、UITableViewだとなにか特殊なコードが必要になるのでしょうか?
viewDidLoadで非表示に設定することはできているので、ボタン押下で表示状態に戻したいです。

該当のソースコード

swift

12import UIKit3 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 = true14 15 }16 17 18 let TODO = ["日本語","English","韓国語"]19 20 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {21 return TODO.count22 }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 2037 }38 39 @IBAction func pu(_ sender: Any) {40 41 // プルダウンの中身を表示42 inPull.isHidden = false43 }44 45}

試したこと・調べたこと

上記の詳細・結果

viewもlabelも
該当View.ishidden = true or false で表示・非表示が可能と出てきました。

補足

xcodeを使用しています。

コメントを投稿

0 コメント