0

I am a new in iOS Development and I can´t move forwards... Is here somebody with experience, who can help me to solve my problem?

I use a Storyboard. First you see a ViewController with buttons. When you click on one of the button, informations about this button appear in a TableViewCell. - until now is it clear.

Than you click on a button "Continue" (than you come back to ViewController with buttons) and choose another button from ViewController.

HOW to do it, that informations from this button comes to a TableView as a second Cell? (so that when you click on for example three of the buttons, they appear as 3 cells under each other in this table?)

My Sample Code is here to download. - (on this website click on the smallest icon "Download").

Thank you very very much for your help!!!

Iva

Iva
  • 47
  • 8

1 Answers1

0

You need a Model to store your selections/data.

For example: On MainViewController, when you click on button1, record that in the Model using array or just variable. Then, when you load SecondViewController, check the values in Model and load cells accordingly.

=> Example code for Model

// Header
@interface ModelData : NSObject

@property (nonatomic) NSMutableArray selectedProducts;
@property (nonatomic) NSInteger value1;
@property (nonatomic) NSInteger value2;
@property (nonatomic) NSInteger value3;

@end


// Implementation
@implementation ModelData

@synthesize selectedProducts = _selectedProducts;
@synthesize value1 = _value1;
@synthesize value2 = _value2;
@synthesize value3 = _value3;

@end

Various options:

  1. Use NSUserDefaults to store information like settings
  2. Use a Model class as described above - it could be a singleton class
  3. Use CoreData to store and retrieve your data - complicated approach and suitable for dynamic things

Here is a reference to a good Data Model tutorial (reported by Iva)

user427969
  • 3,836
  • 6
  • 50
  • 75
  • Thank you very much for your answer! Your answer is for sure a great starting point... The most what I learned until now was from tutorials and some sample code. I found this answer to [Model Data:] (http://stackoverflow.com/questions/7179236/how-to-deal-with-model-classes-in-ios-application). There is also a [sample code.](http://dl.dropbox.com/u/1232650/linked/stackoverflow/SimpleModel.zip).Is it what you mean? Don´t you know some website, which explain me more deeply Models to store selections? Would it be possible to modify my code to see how it functions? Thank you very much!!!! – Iva Dec 11 '12 at 09:07
  • The sample code you provided in the above comment works like native Contacts app. You have a list of contacts and when you click on 1, details of that person are displayed. – user427969 Dec 11 '12 at 21:16
  • From what I understand from your question is I think you are trying to do something like a Settings page, you configure some settings and that is applicable to entire app. If you don't have many options in your MainViewController then you could alternatively use `NSUserDefaults` as well. – user427969 Dec 11 '12 at 21:18
  • For the kind of `Model` as described in my answer, I think you will need to use a `Singleton class` to access or store values. One of the examples on how to implement `Singleton class`: http://www.galloway.me.uk/tutorials/singleton-classes/ – user427969 Dec 11 '12 at 21:22
  • What I want to do is more like a shopping cart. You click on a button Add to a cart and it will send it to the shopping cart in UITableView... I was searching for some tutorials, for some sample code, but I didn´t find something useful. – Iva Dec 11 '12 at 22:18
  • I have updated my answer with various options that you could use. I would suggest to check merits and demerits of all the approaches and see which one is suitable to you – user427969 Dec 11 '12 at 22:48
  • Thank you! I´ll check all options. – Iva Dec 11 '12 at 23:02
  • Because of your answer, I found a great tutorial on a Data Model: http://www.hollance.com/2011/04/making-your-classes-talk-to-each-other-part-1/ So thank you very very much for your answer! – Iva Dec 12 '12 at 20:09
  • Thanks for that. I have updated that in my answer for future reference – user427969 Dec 12 '12 at 21:32