How to make a Reusable TableView?

1

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 ...

    
asked by anonymous 15.12.2015 / 12:07

1 answer

0

I do not understand your question, but I think you want to have another tableview on another screen in the same way as the first one, besides putting it on the storyboard and connecting the outlet's, just insert the delegate and data source after class declaration , create an array with the objects that will appear on the table and start in viewDidLoad, and then set the functions of numberOfRowsInSection and cellForRowAtIndexPath.

    
16.12.2015 / 18:52