无法使UiTableView工作 [英] Can't make UiTableView work
问题描述
我正在开发一个关于XCode 6和Swift的项目。
我需要向UIViewController添加一个UITableView,然后用内容填充表。
I am working on a project on XCode 6 and Swift. I need to add a UITableView to a UIViewController, and then fill the table with content.
所以,在我的默认UIViewController上,我添加了一个UITableView和一个UITableViewCell(使用故事板)。
接下来,我将UIViewController设置为表的dataSource和delegate。
So, on my default UIViewController, I added a UITableView and a UITableViewCell (using the storyboard). Next, I set the UIViewController as the dataSource and delegate for the table.
最后,我将此代码添加到我的视图controller.swift中:
Finally, I added this code to my view controller.swift:
import UIKit
class ViewController: UITableViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var table: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return 3
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = "Hello world"
table.reloadData()
return cell
}
然而,当我运行项目时,我得到了以下日志的崩溃
However, as I run the project, I get a crash with the following log
2015-04-08 21:06:52.820 tableViewTest[12380:783945] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "BYZ-38-t0r-view-8bC-Xf-vdC" nib but didn't get a UITableView.'
我尝试了什么,我真的不知道如何解决这个问题。
I've tried anything, I really don't know how to solve this.
任何人都可以帮助我吗?
Can anyone help me?
推荐答案
你有一个tableview为 IBOutlet
,你需要你的 ViewController
成为<$的子类c $ c> UIViewController 。
You have a tableview as IBOutlet
and you need your ViewController
to be a subclass of UIViewController
.
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {}
这篇关于无法使UiTableView工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!