Contact Us

Use the form on the right to contact us.

You can edit the text in this area, and change where the contact form on the right submits to, by entering edit mode using the modes on the bottom right. 

Oak Ridge, TN, 37830
United States


Populate Table From Array

Wade Cantley

The goal here isn't to simply show how you would manage data read into an array from a model class, and then use it to populate cells in a table view.

//  Created by Chris Cantley on 11/13/14.
//  Copyright (c) 2014 Chris Cantley. All rights reserved.

import Foundation
import UIKit
import CoreData

class LendersViewController: UIViewController {
    //lenders is the array we are going to stick our data into
    var lenders = Array<Lenders>()
    // This is the lendersModel class.  This contains our read/write/udpate/delete methods.  For this example we will use a read method to load the table.
    let lendersModel = LendersModel()

    //MARK: VC Delegate Methods
    override func viewDidLoad() 
        // Get the data from the read function in the lendersModel class when the view loads.  
        self.lenders = lendersModel.readLenderData() as Array

// This extension focusses on containing delegate and custom methods specific to the table view.
extension LendersViewController: UITableViewDelegate, UITableViewDataSource {

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        //return lenderData.count!
        return self.lenders.count

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{

        // Set the cell to reference the LendersViewCell class below.
        //  This contains all the connections to the cell.
        let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(“SomeCell") as UITableViewCell
        var lendersNSArray = lenders as NSArray
        var getData = lendersNSArray[indexPath.row].valueForKey("corpName") as String?

        return cell