I am making an application. On one of the tab I have used tableview on which I am adding the local notifications timing by using time picker. I am also using sql database in my app. Now I want the timing which I have added in the table view must be store in database so that I can retrieve it on another tab. How Can I do this implementation. Please If anyone know it. Give me some solutions.
Thanks alot.
If all you need is to receive the data in an other tab I think storing in mysql is a bit overkill.
What don't you use a shared object that will be used by both tables?
An other simple option will be to store the data in NSUserDefaults
//create an array of all the data in the table view.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:array forKey:#"table data"];
[defaults synchronize];
And in the next tab
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *array = [defaults objectForKey#"table data"];
//pass the array to the table view.
But that really depends on how much data you store and do you need it to be saved when the app is closed.
But the best solution in my opinion will be to use core data.
GOOD Luck
Related
Question: How and where should I store my users information and other global data that comes from the database when the user logs in?
Background: When my user logs into the application I want to do another database call (beyond the authentication process) that grabs a lot of the general global information out of the database and store it somewhere that my application can get it later during different parts of the application.
I am a new iPhone developer so I am always open to other recommendations and feedback.
You can store it in "AppDelegate.h" like declare a array or dict. there and when you got
data assign him.
The Another way is store all your data in NSUserDefault
//Save
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
[userDefault setValue:YourData forKey:#"LoginData"];
[userDefault synchronize];
YourData should be in array or dictnory.
//Get
Array/dict = [[NSUserDefaults standardUserDefaults] valueForKey:#"LoginData"];
:)
You can use
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setValue:#"Value" forKey:#"Key"];
[userDefaults synchronize];
Then Use it,
NSString *st = [userDefaults valueForKey:#"Key"];
Hopefully this will help you
I am making an app that has two tabs, one of which is a "favourite" tab. In the other tab called "search", I have a list of results displayed in a table view, when you tap one, you get to see the detail of that particular result. What I'm trying to do here is, there is a button in the detail view, when it is pressed, the current result gets sent to the "favourite" tab. I tried to use delegate to pass the information, but it didn't work out. Here is my code:
DetailViewController.m
-(IBAction) addSomething {
[self.delegate detailViewController:self addToFavourite:self.something];
}
FavouriteViewController.m, implement the delegate method:
- (void) detailViewController:(DetailViewController *)detailViewController addToFavourite:(Something *)something{
detailViewController.delegate = self;
[thingsList addObject:something];
[theTableView reloadData];
}
Everything is built and fine, but when I click "add" button in the detail view, the data doesn't get sent to "favourite" tab's view. Can anyone help me with this one? Do I need to use core data in this case, I never used core data before. Thanks.
One way to do it that is drop dead easy is storing your information in NSUserDefaults.
NSUserDefaults *defaults = [NSUserDefaults standardDefaults];
[defaults setObject:thingsList forKey:#"myData"];
[defaults synchronize];
When you load your data up in your other tab, just fill it from user defaults.
NSUserDefaults *defaults = [NSUserDefaults standardDefaults];
otherData = [defaults objectForKey:#"myData"];
I probably abuse user defaults more than I should, but it makes for a very easy way to store your data locally and have it persist between runs. It will also backup with iTunes for added persistence. Hope this helps.
I want to save some integers after application shut down and restore them after application opening, what is the easiest way to do this?
You should store and load data from NSUserDefaults:
http://developer.apple.com/library/IOS/#documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// to store
[defaults setObject:[NSNumber numberWithInt:12345] forKey:#"myKey"];
[defaults synchronize];
// to load
NSNumber *aNumber = [defaults objectForKey:#"myKey"];
NSInteger anInt = [aNumber intValue];
Check out the NSUserDefaults documentation. You can set arbitrary key-value pairs there which (as long as you call the shared user defaults object’s -synchronize at some point before your app terminates) will persist between launches.
You can save them in the NSUserDefaults. This is mainly used for preferences.
[[NSUserDefaults standardUserDefaults] setObject:someInteger forKey:#"someIntegerKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
You can also save them to a Property List file if you have more data you'd like to store.
NSDictionary *someDictionary = [NSDictionary dictionaryWithObjectsAndKeys:someInt1, #"someIntKey1", someInt2, #"someIntKey2", nil];
[someDictionary writeToFile:somePath error:&error];
To save upon exiting the app place any code in
- (void)applicationWillTerminate:(UIApplication *)application
Look into using NSUserDefaults. This works like a dictionary that you can add key/value pairs to. You save the variables in your app delegate's applicationWillTerminate and applicationDidEnterBackground methods. You load the variables again in applicationDidFinishLoading.
The easiest way is to use NSUserDefaults. Your app delegate will get an -applicationWillTerminate: message when the app is about to shut down, and you can write your data to NSUserDefaults (or write it into your own file if the amount of data is large). Then, when your app starts up again, your app delegate will get an -applicationDidFinishLaunching, and you can read your data back again.
Serialize them and store them on memory. You have to do this before shut down and load when app is reopened
Greetings,
I am a new programmer in iphone development . i am making an application with Open Erp i require to a login page which occur only the first time the app is run and also a settings page to change it when required.
I have used NSUSerDefaults to access variables around classes but not sure how to save it and log in automatically the second time the app is run.
I appreciate any help available .
Thank you
You can set object for key in NSUserDefaults as
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:username forKey:#"userName"];
and to get from defaults use -
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *user_name = [userDefaults objectForKey:#"userName"];
when you launch your app check for userdefauls for pre saved username if it is nil then display login view otherwise display view that you want.
I want to add a simple note to my app. After searching, I found that I need: a tableView and the active Note's view "please tell me if I'm missing some thing".
What I couldn't find is How and Where to store the notes and how to retrieve it?
Thanks :)
For storing simple objects like strings for notes, take a look at NSUserDefaults.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:#"hello" forKey:#"key"]; // Store value.
NSString *note = [defaults objectForKey:#"key"]; // Retrieve value.
Core data provides a good mechanism for persisting data that is more complex. Check out the guide here: Core Data.