Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Total sum of values in tableview

Hello,

I have a tableview and i would like to sum the totals of all cells in this tableview how can i do that?

thank you verry much

2 Answers

Hello:

Tableviews are fun, but there is a very important step you need to take in order for you to be able to work with them properly. If you design your table with the MVC paradigm, then this sum can be possible. I am not sure how you have yours set up, and what is the purpose of it, but following the MVC paradigm is the way to do it. This may not be the answer you are looking for, since your question is very vague without a proper displayed code and explanation of your goal.

If you want more help, then try to show your code, and perhaps we can be of more assistance.

Good luck.

thank you for your answer Jhoan,

Im trying to build a shopping list with: name and price. How would you do this.

thank you

Mo,

You have to follow the MVC paradigm, if you have taken the courses in here, there is a build a play list app, that shows you how to follow that. Also you can find a lot of information about that with a google search.

Basically you want to do 3 things.

  • A custom class that will create your shopping list with name and prices, as objects.
  • A tableviewcontroller which will act as the middle man between your custom class and the custom cell.
  • A custom cell.

Model View Controller: (MVC)

  • Model: Will be your custom class.
  • View: Will be your cell.
  • Controller: Will be your TableViewController.

This is just a basic information, you may want to dig deeper.

Good luck.