我一直在努力弄清楚這是如何工作的,但我似乎無法得到它。我曾嘗試過使用其他教程,但隨着許多測試版本的發佈,一切都在不斷變化。我對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