Serialization with objective-c - iphone

I'm doing a iphone application and when the user quit the application and return in the application later, I want he return at the same place in the application before he quit. How I do this? Is it serialization?
thanks
Alex

It's a little different than serialization. What you want to do is save the app details in NSUserDefaults. For example, if you have a tab view, save the index of the last tab used in the user defaults.
If you have a table view, you can use serialization to save the actual information in the table to present back to the user when they start the app again.

Related

How would you save user's profile data from firebase in cache Swift

I have a view controller that is basically the average user's profile on any social media app (showing data like their name, followers, following, name, bio and profile picture). I have successfully made it so all the relevant data get's retrieved from my firebase database.
However, whenever I go out of that view controller and back in again, from the profile screen to a post and back to their profile screen, it reloads all the data again which caused the hard coded values of the profile like 'Name' for the name label to show every time they go out and back into the view controller.
So my question is, how would I retain all the data in a cache - I guess, so it looks like its only loaded the data once (obviously in the background it will check for a change every time you reload the view).
If i'm correct you can solve that problem for string based values (like their name and followers number) by using the firebase offline capabilities? How would I do the same for stuff like their profile picture? Save the picture in a cache and then update it whenever there's a change?
Thanks,
Nathan
EDIT: Here's a video of my problem: here as you can see in the video, when you go back out of the view controller, and then back in, the image has to be loaded again. Is there any way to save that imaged to a cache so the next time the profile is opened it will already be there.

How to get user input with UITextView in different cells in UITableVIew

so I have a UITableView and within each cell, a UITextView. I want the user to be able to edit each UITextView as many times as they like, then go back to somewhere else in the app, close the app, whatever, and then come back and see the same thing they wrote. I have not been able to figure out how to do it.
Please help. I'm still pretty new to Swift.
This is a design problem. Anyway my suggestion is to add a flag in your data model.
Data model (the data that you are presenting in your table). If you don't have any data model, add one.
Example:
class UserInformation {
name: String
isEditing: Bool = false
}
and then save this in your preferred location either in DB (core data, realm etc) or plist (which i don't recommend)
now during the creation of cell. You could just check if this is in editing mode. And then fill up the text field using the saved data.
EDIT: You can't just magically know/retain a state in an object without persisting.
You want to store textView informations in any case, including terminating application, there are some steps to implement this feature.
At first, you have to pick up a place for storing your information:
Hard disk
Your own server
Other service (firebase ...)
RAM is not useable in this case.
Supposing you like hard disk option, let's select a method for storing:
Create a file (JSON, text file, ...), save your information every time user enter a new one, open it to get information back.
Save it by CoreData / Realm in database way (CoreData is like SQL lite, a lite weight database for mobile application supported by Apple)

Load String automatically on launch

Hey everyone, I have a little issue that I can't seem to figure out. What Im trying to do is have pre-saved values automatically put into the textfields on launch. Right now, I have the user filling out the fields, then pressing a save button. At next launch, the user needs to press the load button, how do i eliminate that load button?
In your Save button action, do this ...
[[NSUserDefaults standardUserDefaults] setObject:myKey1TextField.text forKey:#"key1"];
... and in your viewWillAppear method do this ...
myKey1TextField.text = [[NSUserDefaults standardUserDefaults] stringForKey:#"key1"];
... viewWillAppear is not the only place where you can place it. It depends on how frequently these data are changed, if they can be changed in background, etc.
Look at the NSUserDefaults API.
Basically you save your content with key/pair, so when your app is launched you just retrieve these values.
I did something like this the other day but i am using core data. I just stored the previous value my core data file and read it back the next time the app launches, lot of mucking around if you don't have core data already but just putting it out there for anyone with a similar problem

Applying user-entered data in one view to a second view

I'm trying to write an iphone OS app that includes a logbook feature. The problem that I'm having is that I want each new logbook to have its own categories that are user-defined, for example a chemical receipt log would have chemical name, vendor, receipt date, expiration date and comments.
The way that I'm trying to go about this is by calling an editCategory view controller when a new logbook is created that contains a number of UITextields where the user can enter the categories. I want to take those strings and apply them to a newLogEntry view controller, so that when the user creates a new log entry, they are presented with each category followed by a UITextfield so they can enter the relevant data.
The trick is, I have no idea how to grab the category data from editCategory and apply it to newLogEntry. I'm currently using Core Data, as that seems to be the easiest way to go about this, but I'm not married to it if it interferes with a good solution. Also, I'm still more comfortable with genetic code than objective-C code, so please bear with my ignorance.
Have you considered using the App Delegate? You could keep those values in the App Delegate, and call on them in the ViewDidLoad method of your newLogEntry view controller.

Supress visible screen switching on iPhone

In the iPhone application I'm developing, I have a need to return the user to the previous screen they were using when, for instance, the application was interrupted by, say, a phone call.
The application is driven by a navigation controller, and the user may be several layers deep into the application. As such, I think that I need to traverse the navigation controller logic to bring the user to the point that they were previously at, with all return navigation logic n place.
I'm comfortable that I can force the application to navigate down to the required level through code, but I would like to hide the screen switching and animations that would occur while this is going on, thus presenting the user with (apparently) a direct path to their last used screen, rather than showing them the underlying navigation that's occurred.
Could somebody please point me to some method of suppressing the intermediate displays?
Does anyone have other methods to perform this sort of task?
Thanks in advance for all suggestions.
I suggest you take a look at the Three20 project which contains a feature called "URL-based navigation", which might help you, since you only should to store the URL of the current visible view controller, and restore it when the app resumes after the phone call:
TTNavigationCenter is for those grizzled old web developers like myself who want to organize their app by "pages" which can be displayed by visiting a URL.
Your view controllers can simply register URL patterns that they handle, and when those URLs are visited the controllers will be created and displayed. You can also register generic actions that are called when a URL is visited.
TTNavigationCenter also persists and restores the full path of navigation controllers and modal view controllers, so your users can quite the app and come back exactly where they left off.
(source: Three20 Github project)