How do I iterate through an array and display the contents of the array in a Table View?
I have the table view all setup but when I write the for in loop it just displays contents in the first row.
For example, I am making a loan calculator and I want the table view to display every months principal, interest, and balance all the way through the term of the loan like this:
1. P: $$$$$, I: $$$$$, Bal: $$$$$
2. P: $$$$$, I: $$$$$, Bal: $$$$$
3. P: $$$$$, I: $$$$$, Bal: $$$$$
4. P: $$$$$, I: $$$$$, Bal: $$$$$
5. P: $$$$$, I: $$$$$, Bal: $$$$$
I cannot get it to do this.
This is what I get:
60. P: $$$$$, I: $$$$$, Bal: $$$$$
Also, how do I get row 2 to calculate off of row 1 and row 3 to calculate off of row 2 and so forth.
Thank you
Your code is broken and I need to guess some parts, which makes hard to write a right answer. Also, your loan calculation seems to be broken...
But the reason you get only one row in your table view is clear enough.
In your line 56.
data = ["\(paymentNumber). P: \(fResultPrincipal), I: \(fResultMonthlyInterest), Bal: \(fResultBalance)"]Your whole `data` is replaced by a single-element Array `["\(paymentNumber)..."]`.
You may need to add another element for each iteration of your for-in statement, instead of replacing whole contents.
data = []
for _ in 1...intMonths {
paymentNumber+=1
//You may need to calculate fResultPrincipal, fResultMonthlyInterest and fResultBalance here.
//...
data += ["\(paymentNumber). P: \(fResultPrincipal), I: \(fResultMonthlyInterest), Bal: \(fResultBalance)"]
}