UITABLEVIEW showing last value of loop?


#1

I would like to show all the values of this loop in the tableview, how can I do that? this is my code:

import UIKit

class tableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    
    @IBOutlet var tableView: UITableView!
    
    var arr = [Int]()
    var cell:tableCell!
    var TPayment: float_t!
    var years1: float_t!
    var monthlyPayment: float_t!
    var interest: float_t!
    var principil: float_t!
    var interestrate: float_t!
    var initil: float_t!
    var data = Array<float_t>()
    var data2: NSMutableArray = []
    // Initialize the Dictionary
    var keys = []
    
    // Get array of values
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.delegate = self
        
        tableView.dataSource = self
        
        let c = Int(years1)
        arr += 0...c
        
        tableCalculation()
        
            // Register custom cell
            let nib = UINib(nibName: "table", bundle: nil)
            tableView.registerNib(nib, forCellReuseIdentifier: "cell")
            
            
        
    }
    
    func tableCalculation() {
        
        let years = Int(years1)
        initil = TPayment - 0
        
        for i in 0..<years {
//            initil == initil 
            
                initil = initil - principil
                
                interest = initil * interestrate
                
                
                
                principil = monthlyPayment - interest
                
                print("Month : \(monthlyPayment),   principil: \(principil),interest: \(interest), initi: \(initil)")
                data = [interest]
                self.data2 = [initil]
            
            
            
            
            
        }
        
    }
    // 2
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return arr.count
    }
    
    
    // 3
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 	{
        
        cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! tableCell
        cell.lbl1.text = "\(arr[indexPath.row])"
//        tableCalculation()
        
        cell.lbl2.text =  currencyFormatter(monthlyPayment)
        cell.lbl3.text = "\(data[indexPath.row % data.count])"
        cell.lbl4.text = currencyFormatter(principil)
        cell.lbl5.text = "\(self.data2[indexPath.section])"
        
        return cell
        
    }
    
    // 4
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        print("Row \(indexPath.row) selected")
    }
    
    // 5
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 40
    }
    
    func currencyFormatter(Price: float_t) ->String {
        
        let currencyFormatter = NSNumberFormatter()
        currencyFormatter.usesGroupingSeparator = true
        currencyFormatter.numberStyle = NSNumberFormatterStyle.DecimalStyle
        // localize to your grouping and decimal separator
        let numberOfPlaces: float_t = 1.0
        let multiplier: float_t = pow(10.0, numberOfPlaces)
        let num = Price
        let rounded = round(num * multiplier) / multiplier
        let priceString = currencyFormatter.stringFromNumber(rounded)
        
        return priceString!
    }
    
}