【发布时间】:2016-12-03 12:44:05
【问题描述】:
我在 main.storyboard 中放了一个UINavigationController 并将其命名为“TableViewController”,并将原型单元格命名为“Cell”。一切都很清楚,构建成功,但没有任何东西可以显示表格视图,而是显示一个白色的空白表格视图。请建议我一个解决方案或您的想法。
这是 ViewController.swift 中的代码:
import UIKit
class TableViewController: UITableViewController {
struct Objects {
var sectionName : String!
var sectionObjects : [String]!
}
var objectsArray = [Objects]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
objectsArray = [Objects(sectionName: "General", sectionObjects: ["150/23","A: 98","W: 76","B: 89", "Quantity: 5kg"]),Objects(sectionName: "General", sectionObjects: ["150/23","A: 98","W: 76","B: 89", "Quantity: 5kg"]),Objects(sectionName: "General", sectionObjects: ["150/23","A: 98","W: 76","B: 89", "Quantity: 5kg"]),Objects(sectionName: "General", sectionObjects: ["150/23","A: 98","W: 76","B: 89", "Quantity: 5kg"])]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView , cellForRowAtIndexPath indexPath: NSIndexPath) ->UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier:"Cell") as UITableViewCell!
cell?.textLabel?.text = objectsArray[indexPath.section].sectionObjects[indexPath.row]
return cell!
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return objectsArray[section].sectionObjects.count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return objectsArray.count
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?{
return objectsArray[section].sectionName
}
}
【问题讨论】:
-
swift 3.0 和 2.0?
-
你的细胞正在制造吗?检查调试视图层次结构。
-
我猜你的意思是
UITableViewController,而不是UINavigationController。 -
swift 3.0 @HimanshuMoradiya
-
@shallowThought 我该怎么办?用类第 2 行中的 UINavigationViewcontroller 替换 UITableviewcontroller?我替换它给出了错误
标签: ios swift uitableview tableview