Проще всего было бы создать новый Swift, или цель C Class и продлить UITableViewController с ним ... Это создаст вам идеальный образец кода о том, как написать UITableView DataSource и делегат, которые можно было бы просто скопировал ...
После этого установите ваши UITableViews делегата и DataSource свойства личности в viewdidload и реализации UITableViewDataSource, UITableViewDelegat
Редактировать
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var myTable: UITableView!
var myDataArray: NSArray!
override func viewDidLoad() {
super.viewDidLoad()
myDataArray = NSArray(objects: "Peter", "Paul", "Marry")
myTable.dataSource = self
myTable.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
//MARK: TableView DataSource
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return myDataArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("Cell") as? UITableViewCell
if (cell == nil) {
cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
}
cell?.textLabel.text = myDataArray.objectAtIndex(indexPath.row) as NSString
return cell!
}
//MARK: TableView Delegate
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
}
Я быстро проводной вас некоторые Swift Пример кода, где вы можете увидеть, как подключить вид таблицы, с DataSource и делегат вас класса ...
Пожалуйста, голосуйте меня, если она помогла вам :-)
Провести урок или учебник. – Andy