Swift 4.0
Xcode 9.1
以下のような記事を参考にTableViewのセクションわけを作成しましたが、画像のように一つ目のセクション?しか表示されません。どこに問題があるのでしょうか?
そもそも、引数の section
なるものはどこから取ってきているのか疑問です。
http://docs.fabo.io/swift/uikit/019_sectionuitableview.html
https://i-app-tec.com/ios/tableview-cell.html
import UIKit class SettingsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { let firstOptions: Array = ["設定"] let secondOptions: Array = ["設定"] let sections: Array = ["hoge", "foo"] func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "ConfigCell", for: indexPath) if indexPath.section == 0 { cell.textLabel?.text = "hogehoge" } else if indexPath.section == 1 { cell.textLabel?.text = "hogehoge" } return cell } func numberOfSectionsInTableView(tableView: UITableView) -> Int { return self.sections.count } func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return sections[section] } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if section == 0 { return firstOptions.count } else if section == 1 { return secondOptions.count } else { return 0 } } override func viewDidLoad() { self.navigationItem.title = "設定" super.viewDidLoad() } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/06 01:47