Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-18-2011, 06:34 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Location: Atlanta, GA
Posts: 148
tripp13 is on a distinguished road
Question Using coreData and adding (math word) the previous row with the new row?

I'm nearing the end of my first app and hope it does well. I think it's put together well, but one of my last steps deals with a fairly complex algorithm that calculates each time the user updates and provides the new values once an action is done. I'm using core data and actually like it a lot. I was dreading it initially based on a lot of the posts I read, but it's grown on me. I digress.

So, each time the user enters a new value, that value is displayed in the tableView. since the user can theoretically enter an infinite amount of rows, hard coding is out of the question. I created a bunch of labels and textfields in a different project with the same premise to test the algorithm for correctness and it checked out.

So, could somebody help me out a little and explain / point me in a direction to add tableviewcells together. for example:

(The right side of the = are integers...I know what they really are, but just simplifying for the sake of the example and so someone can understand what i'm attempting to do. This is a mathematical issue.)

indexPath.row 0 = 1
indexPath.row 1 = 2
indexPath.row 2 = 3

The answer i would want would be 6...1 + 2 = 3...3 + 3 = 6.

I really do appreciate the guidance. Please let me know if you need any clarification. Thanks, y'all.
tripp13 is offline   Reply With Quote
Old 03-18-2011, 07:26 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 1,106
Meredi86 is on a distinguished road
Default

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
Meredi86 is offline   Reply With Quote
Old 03-18-2011, 01:07 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2010
Location: Atlanta, GA
Posts: 148
tripp13 is on a distinguished road
Default

Meredi, thanks a bunch for the time you put in. Can't wait to test it out when I get home.

I Figured I'd be pulling from the data model, but didn't quite know how to call that data for the individual rows that data is saved in. I do appreciate it.

I was wondering if this way might work and would like your opinion if you have the time.

Could I setup a separate Formulas entity with a fetch request or relationship that sucks the needed values from the firstTableView's Model and another relationship to the secondTableView's Model and base the calculations off of that? Just thinking right now.

One last question, I think I answered it for myself, I can't have the previous totals change and need them to stay constant unless a previous (not a current and not a future) value is changed by the user. I would just set a sum object for each entity that is created, right?

Thanks again. What you said makes sense and is fairly obvious once you said it. Thank you.
tripp13 is offline   Reply With Quote
Reply

Bookmarks

Tags
algorithm, coredata, math, tableview sections, tableviewcell

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 349
12 members and 337 guests
7twenty7, chiataytuday, condor304, Creativ, Domele, dreamdash3, laureix68, LEARN2MAKE, michelle, mistergreen2011, Sami Gh, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,661
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, tinamm64
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:30 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0