Em 90% das minhas telas irei precisar de uma tableview para preencher o conteúdo, como posso fazer esta tableview reusável ? digo como posso simplificar a inserção desta table em várias views, meu código é o seguinte:
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak
var tableView: UITableView!
var textArray: NSMutableArray! = NSMutableArray()
override func viewDidLoad() {
super.viewDidLoad()
self.textArray.addObject("Exemplo1.")
self.textArray.addObject("Exemplo2.")
self.textArray.addObject("Exemplo3.")
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 44.0
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) - > Int {
return self.textArray.count;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) - > UITableViewCell {
var cell: UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
cell.textLabel ? .text = self.textArray.objectAtIndex(indexPath.row) as ? String
return cell
}
}
Fora o trabalho da Main.Storyboard que é colocar uma tableView, colocar o auto-layout inserir o Identifier e colocar o @IBOutlet...