简体   繁体   中英

How to fill TableView with data from another ViewController

I want to fill a tableView with some data (Strings), that I save in another View/ViewController.

My viewDidLoad of the SaveViewController:

NSString *savestring = @"Test: This is a test!";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:savestring forKey:@"savedstring"];
[defaults synchronize];
  1. Is this a good way to save data? (It's very easy so I am using it at the moment)

Now I am having another View (TableView), that should fill with this string dynamically. (I want to add the date and some string, it should be something like a training journal)

2 . How can I do this? Should I change my "saving" ?

No NSUserDefaults is not a good place to save data with the exception of storing a few user preferences. You should look into using Core Data for your general storage needs.

You can also save to plists which depending on your data can be simpler eg you just need to store a single dictionary.

You can sore this changes in some model object. Than you can send this object using delegate, or u can create singleton app manager with general model object. If you want to save this data to database, you should read about CoreData.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM