0
私のコントローラに2つのグループ化されたテーブルビューセクションを提供しようとしています。現在、最初のセクションとそのヘッダーは正しく表示されていますが、2番目のセクションは見当たりません。両方のセクションはかなり簡単で短く、フレーム内に完全に収まる必要があります。Swift - テーブルビューの2番目のセクションが表示されない
2番目のグループはどこに行きましたか、どのようにして最初のグループの下に表示させることができますか?
import UIKit
struct SectionData {
let title: String
let data: [String]
var numberOfItems: Int {
return data.count
}
subscript(index: Int) -> String {
return data[index]
}
}
extension SectionData {
init(title: String, data: String...) {
self.title = title
self.data = data
}
}
class SettingsController: UITableViewController {
let cellId = "cellId"
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.dataSource = self
self.tableView.delegate = self
self.tableView.isScrollEnabled = false
self.tableView.tableFooterView = UIView(frame: CGRect.zero)
self.tableView.backgroundColor = UIColor(white: 0.95, alpha: 1)
self.tableView.rowHeight = 60
}
lazy var mySections: [SectionData] = {
let section1 = SectionData(title: "INFORMATION", data: "About the app", "Our website", "Twitter", "Call us")
let section2 = SectionData(title: "SUPPORT", data: "Report a problem", "Privacy Policy")
return [section1, section2]
}()
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return mySections.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return mySections[section].numberOfItems
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return mySections[section].title
}
override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
let header = view as! UITableViewHeaderFooterView
header.textLabel?.font = UIFont(name: "Futura", size: 16)!
header.textLabel?.textColor = UIColor.darkGray
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 40
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellTitle = mySections[indexPath.section][indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) as UITableViewCell
cell.selectionStyle = UITableViewCellSelectionStyle.default
cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
cell.textLabel?.text = cellTitle
return cell
}
}
ありがとうございました!それは今働いている。 Xcodeがそれについて私に知らせなかったのは、奇妙なことです。それは通常Swift 3の設定が変更されたために何かを変更するように指示します。これを答えとしてマークします。 –
@DennisvanMazijkようこそメイト:) –