Dodajesz nową zmienną instancji tableview poniżej deklaracji klasy.
@IBOutlet
var tableView: UITableView!
Aby zachować zgodność z protokołem UITableViewDelegate
i UITableViewDataSource
prostu dodać je oddzielone przecinkami po UIViewController
w deklaracji klasy
Potem musimy wdrożyć tableView(_:numberOfRowsInSection:)
, tableView(_:cellForRowAtIndexPath:)
i tableView(_:didSelectRowAtIndexPath:)
metod w klasie ViewController
i pozostawić ich teraz pusty
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
...
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 0 // your number of cell here
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// your cell coding
return UITableViewCell()
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
// cell selected code here
}
}
odnieść ten link http://www.ralfebert.de/tutorials/ios-swift-uitableviewcontroller/ https://www.weheartswift.com/how-to-make-a-simple-table-view-with -ios-8-and-swift/ –
@DharmeshDhorajiya Świetnie, działa! "weheartswift" ma odpowiedź – Eliko
Witaj w każdej chwili @Eliko ci, co jest w porządku na google. –