I have a database with a lot of private messages (PMs). PMs can be stored in different folders, like Emails (send, inbox, folders) and so on. To cut a long story short: I want to rebuild the iPhone Email-app for my private messages in my database, which I can get with a JSON query (wrappe开发者_JAVA百科r is allready implemented and working perfect).
How to rebuild this?
Features I wanna have is PMs should be stored in a kind of cache on the iphone, so that user can read them without haveing internet.
Any idea, how to rebuild the design and how to add this cache functionality?
Design
The Mail.app uses a UINavigationController
for navigating trough the several views.
- Accounts-view:
UITableViewController
. - Account-view:
UITableViewController
showing anUIToolbar
. - Mails-view:
UITableViewController
showing anUIToolbar
. - Mail-view:
UIViewController
consisting of anUIWebView
(which shows the actual mail) and anUIToolbar
.
Caching
You should implement NSCoding
to every class you write (so something like KVMail
, KVAccount
, etc.).
Then, when the 'database' has been changed, you save all the records in NSUserDefaults
, like this:
NSArray *accounts;
- KVAccount *someAccount;
- NSArray *mails;
- KVMail *mail;
- KVMail *mail;
- KVMail *mail;
Say your design looks like this (so an array of accounts, where every account consists of an array of mails).
When you implement NSCoding
you can save the database like this:
[[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:accounts] forKey:@"database"];
Now, when the user starts the app again, you can load it back into your RAM by doing this:
NSArray *accounts = [NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] objectForKey:@"database"]];
精彩评论