TTLauncher save items position - iphone

I am using TTLauncherView and adding items to it dynamically.
My items are added but once I close the application they are not saved.
I am using a plist to save the items.
In my viewDidLoad, I am using this line _launcherView.pages = [NSArray arrayWithObjects:array, nil];
to load items on TTLauncherView from plist. But this line is throwing exception.
I would really appreciate if anybody can throw some light on it. May be if someone can share the code of how to save added items and their changed positions, if they already have succeeded in doind it.
Any help would be appreciated!
I also looked to this links, but no luck!
dynamically add Items to TTLauncher

This is an old post, so I won't spend too much time here, but if you are already loading your plist successfully, you have (at least) two options: 1) re-save the plist in your documents directory, (making sure to load it from there if it exists), or 2) store your plist data in NSUserDefaults when it has been changed (again, checking NSUserDefaults before loading the original plist).
Hope you figured this all out long ago.

Related

iPhone application preferences

I've been doing some research and so far I've been unable to find out how to display a Settings.bundle inside an application. The guides that I found are:
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/Preferences/Preferences.html
http://blog.webscale.co.in/?p=274
http://knol.google.com/k/iphone-sdk-application-preferences#
These all seem to skip a step: How to display the plist from a view in your application. I've got my view set up and my plist file set up, but I have no idea how to display the preferences plist from the view. Do I manually load everything and put them into labels, switches and whatnot?
This may seem like a stupid question but I honestly don't know. Would anyone be able to explain this to me?
Thanks in advance
EDIT: To clarify; I've found out that this allows me to access the preferences through the settings app. However I want to access these through a tab in the app itself.
http://knol.google.com/k/iphone-sdk-application-preferences#Step_4(3A)_Retrieving_Values_of_Settings appears to describe exactly how to access these...
It's a one-liner so i'll paste it here:
NSString* settingValue = [[NSUserDefaults standardUserDefaults] stringForKey:#"<Setting Key>"]
There's no magical setting key that you have to use. Use whatever you like, and it'll be there the next time the application loads.
I got the same problem; I have an application with a tabBarController as the RootController of my application and, separately, I have a settings menu (loaded from plist) available through the applications preferences of the device.
I do want to include this settings menu into my app as an other view for my tabBarController in order to avoid to have to exit my application to change the settings.
Finally, I have the plist file ready, I just want to know a way to do something like
[C#]
settingsController.View = UIView.LoadFromPList("settings.plist");
tabBarController.addController(settingsController);
... anybody knows ?

Where am I going wrong with localizattion?

I have a plist file that contains numerous arrays, dictionaries, dictionaries that contain arrays of strings etc.
I perform the following steps:
clean poject
reset simulator
run app and all works fine
I add a Spanish localization to the plist file resulting in two identical plist files as I have not made any changes yet
clean project
reset simulator
run app and things go wrong!
For a start off the toolbar that gets its colour like this:
[self.navigationController.navigationBar setTintColor:[UIColor colorWithRed:0.745f green:0.176f blue:0.306f alpha:1]];
is now black?
I also have three20 launcher view in place that now has no buttons visible?
Im at a loss as all I have done is create a localized version of the plist but as yet made no changes in it......so what am I doing wrong?
thanks
You can localize plists, just found this link:
http://www.noorselijster19.com/2011/02/ios/localized-plist/
Using that example I replicated the structure in my plist and go a desired result.
So something is amis in the larger content of the plist file.....

Keeping variable values when the iPhone is shut-down?

Lets say i have an application which has three text-fields, and i can type whatever i want into them, lets also assume that i have a checkbox and a button. And if the button is tapped while the checkbox is checked, the nsstring values in these textfields should get saved somehow. Lets say i power down my iPhone and restarted it, opened the app once again and wanted those values to be in their respective textfields.
How does one do this?
Is this a case for NSUserDefaults or something for Apple's own Keychain API to handle?
Cheers.
Edit: We used local declarations when setting and getting the values of the NSUserDefaults, which of course, doesnt work. It works perfectly now...
Yes you can make use of NSUserDefaults
Integrate a sqlite3 database into ur app.. save the textfields value in an array and sav it in the database. On starting of the apps just load from the database and retrieve the top most array and show the values back as output.. Hope it helps.. I am new also.. but cant think of anything else if u want to restart ur whole phone and still wants the fields to be filled.
Use NSUserDefaults for stuff that doesn't need to be stored securely and Keychain if it does.
You can use the NSUserDefaults or a PList or a database to save the content.
Example is given below:-
[[NSUserDefaults standardUserDefaults] setObject:#"Jayahari" forKey:#"userName"];
PList can be used for archiving, serilizing. Database also can be used for same purpose.

iPhone Localization: simple project not working

Im doing my first localized project and I've been fighting with it for several hours with no luck.
I have to create an app that, based on the user selection, shows texts and images in different languages.
I've read most of Apple's documents on the matter but I cant make a simple example work.
This are my steps so far:
1) Create a new project.
2) Manually create a "en.lproj" directory in the projects folder.
3) Using TexEdit create file called "Localizable.strings" and store it in Unicode UTF-16. The file looks like this:
/*
Localizable.strings
Multilanguage02
Created by Gonzalo Floria on 5/6/10.
Copyright 2010 __MyCompanyName__. All rights reserved.
*/
"Hello" = "Hi";
"Goodbye" = "Bye";
4) I drag this file to the Resources Folder on XCode and it appear with the "subdir" "en" underneath it (with the dropdown triangle to the left). If I try to see it on XCode it looks all wrong, whit lots of ? symbols, but Im guessing thats because its a UTF-16 file. Right?
5) Now on my view did load I can access this strings like this:
NSString *translated;
translated = NSLocalizedString(#"Hello", #"User greetings");
NSLog(#"Translated text is %#",translated);
My problem is allowing the user to switch language. I have create an es.lproj with the Localizable.strings file (in Spanish), but I CANT access it.
I've tried this line:
[[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:#"es", nil] forKey:#"AppleLanguages"];
But that only works the NEXT time you load the application. Is there no way to allow the user to switch languages while running the application??
Do I have to implement my own Dictionary files and forget all about NSLocalizableString family?
Thanks for ANY advice or pointers.
Gonso
There is already a discussion about that here.
Their suggestion is to create a sub-bundle and then use a method called NSLocalizedStringFromTableInBundle(...) (as described in the reference manual) to
get a localized string from a specific table in a bundle.
I am just giving you an hunch, I haven't tried but, I guess, this could be a good way to face your problem.

How I do to call a nib file at only first launch of my application?

I'm new here but I'd like to learn very well iPhone SDK...
I'm making an iPhone app where I'd like to show a modalView controller at launch of my app... How can I do this?
In this modalView, I request some informations and the view must appear only when these informations aren't saved!
Anyone can help me?
P.S.: Sorry for my bad English but I'm Italian... :D Thanks!
First, try to avoid to use NSUserDefautls as it's not application specific and can cause troubles under some circumstances (see reference docs).
I'd suggest to save your app specific data to some plist file for which you can check for at app startup -(void) applicationDidFinishLoading: method of your app delegate class - and decide if your modal view should be shown or not.
Let's say you have application wide accessible
NSMutableDictionary instance where you store your
preferences. When app is about to quit i.e. - (void)
applicationWillTerminate: method of your app delegate, simply store content of that dictionary to plist somewhere under you app directory structure (Documents folder is a good choice). See NSDictionary reference on how to store/read plist files. It's pretty simple.
Typically, you check for your saved data and if it's not there, you assume that it is the first run.
Thus, you first need to decide how you are going to persist data:
User defaults (NSUserDefaults).
Store a file. Typically a property list (plist) in the Documents directory.
Core Data.
I'd like to use NSUserDefaults...