UITableView Showing last value of a loop

后端 未结 2 478
有刺的猬
有刺的猬 2021-01-26 06:09

I would like to show all the values of this loop in the tableview. The code is to calculate an Amortization Table for loans. I tried saving the data of the loop in the array, bu

2条回答
  •  时光取名叫无心
    2021-01-26 06:49

    The main issue is with your data array.

    In your loop where you populate your data array, in tableCalculation, there's this:

    data = [interest]
    

    It means that for each iteration you set the data array to [interest] instead of appending the new item to the array.

    What you should do instead:

    data.append(interest)
    

    Note that you make the same mistake with self.data2. But now you know how to fix this kind of error.

提交回复
热议问题