On 90% of my screens will I need a tableview to populate the content, how can I make this tableview reusable? I would like to simplify the insertion of this table into several views, my code is as follows:
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
}
}
Outside of the MainStoryboard's job that is putting a tableView, putting the auto-layout insert the Identifier and putting the @IBOutlet ...