i have a similar method in my app. I have coredata that stores -well data :P -and one attribute is a numeric value (i think it is actually stored as a string but thats no issue here). What i needed to do, was once the user had input their items (similar to yours - it could be 1 it could be 1000+) and gone onto the next view the numbers would all be added together and the total displayed on screen.
I did this taking a different approach to what you seem to be looking at at the moment. Instead of adding what is in the tableview i have added what is in the CoreData attribute list.
So the way i went around this was something similar to this:
Quote:
fetch an array from my core data entity
use the "count" method on that array to find out how many numbers i will have
loop up my count and during this loop:
assign a "current object" (i.e. set a variable "currentObject" to the current array index)
assign a "singleObject" (i.e. now i have my "currentObject" (an array of items from one coredata row) assign the "valueForKey" to "singleObject")
--- In my case convert the current number (formatted as NSString) to a floatValue (i need decimals)
Add the current number to a new array
|
So by this point i have taken out all of my required numbers from my coredata entity, then assigned them to a new array, leaving me with only an array of floats. Next:
Quote:
use another for loop to add up the numbers in the array. my loop here looks similar to this:
Code:
for (number in array) {
float aFloat = number
sum = sum + aFloat
}
|
At this point "sum" should contain the total value of all the numbers in the array added together.
Hope i have explained clearly and that it helps you out