我一直在努力弄清楚这是如何工作的,但我似乎无法得到它。我曾尝试过使用其他教程,但随着许多测试版本的发布,一切都在不断变化。我对IOS开发相当陌生,所以我很挣扎。如何使用Swift将项目添加到UITableView?
故事板中我有UITableView,它包含一个标识符为“myCell”的单元。
这是我到目前为止。当我运行IOS模拟器时,表格视图上没有任何提示。
有关如何解决此问题的任何建议?
class ViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = "Cell #: \(indexPath.row)" // display the row number
return cell
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10; // testing out with 10 cells
}
}
您运行的是哪个版本的Xcode?我无法按原样编译。 – Mike 2014-09-04 21:10:19
新版本发布。 Xcode 6 Beta 7. – xNightxOwl 2014-09-04 21:14:21