如何在swift 3的表格视图中显示数据?

在这里,我需要传递数据到表视图来显示和获取大量的错误任何人都可以帮助我如何实现这里键应显示为节标题标题和内部值应显示在行

这是数组的声明

var finalDict = [String: [String]]() 

数组的输出如下所示

 ["Flat Rate": ["Fixed", "Base", "Fixed two"], "Best Way": ["Worldwide Express Saver one", "Table Rate", "Worldwide Expedited", "Worldwide Express Saver"]] 

这是表格视图的代码

 func numberOfSections(in tableView: UITableView) -> Int { return finalDict.count } func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { let names = self.finalDict.keys return names[section] } func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { let header = view as! UITableViewHeaderFooterView header.tintColor = UIColor.white header.textLabel?.textColor = UIColor.darkGray header.textLabel?.textAlignment = NSTextAlignment.left header.textLabel?.font = UIFont(name: "Futura", size: 17) } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { let names = self.finalDict.keys let a :[Any] = finalDict[names] as! [Any] return a.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "shippingCell", for: indexPath) as! ShippingMethodTableViewCell let key = self.keys[indexPath.section] progressIcon.stopAnimating() progressIcon.hidesWhenStopped = true var a :[Any] = arrayss[key] as! [Any] var dictionary = a[indexPath.row] as! [String:Any] let price = dictionary ["price"] let name = dictionary["name"] let namePrice = "\(name!)" + " \(price!)" cell.methodLabel.text = namePrice cell.radioButton.addTarget(self, action: #selector(paymentRadioAction(button:)), for: .touchUpInside) if chekIndex == indexPath { cell.radioButton.isSelected = true } else { cell.radioButton.isSelected = false } return cell } 

对于初学者来说,更新下面的数据源方法

 func numberOfSections(in tableView: UITableView) -> Int { return finalDict.count } func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { let titles = Array(finalDict.keys) return titles[section] } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { let titles = Array(finalDict.keys) let currentTitle = titles[section] let values = finalDict[currentTitle] as! [String] return values.count } 

请尝试用Array(self.finalDict.keys)replaceself.finalDict.keys