Si aggiunge una nuova variabile di istanza tableview sotto la dichiarazione della classe.
@IBOutlet
var tableView: UITableView!
per conformarsi al protocollo di UITableViewDelegate
e UITableViewDataSource
basta aggiungere li separati da virgole dopo UIViewController
nella dichiarazione della classe
Dopo di che abbiamo bisogno per attuare le tableView(_:numberOfRowsInSection:)
, tableView(_:cellForRowAtIndexPath:)
e tableView(_:didSelectRowAtIndexPath:)
metodi nella classe ViewController
e lasciare per il momento sono vuoti
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
}
}
fonte
2015-07-29 04:26:12
fare riferimento a questo 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 Ottimo, funziona! "weheartswift" ha la risposta – Eliko
Benvenuto in qualsiasi momento @Eliko, tutto questo va bene su google. –