Luai Kalkatawi
Luai Kalkatawi

Reputation: 1492

Loading every different user own data

I am making an app that the user could add many accounts and view it in the UITableView and I am holding the name via NSUserDefaults and once the name is clicked in the UITableView it will open a different page that has many data fields to fill which is DONE.

For example when the user click on John or other name. The user could see his own data. My problem is that how could I show for every user his own data? Also could I make this via NSUserDefaults ?

It smiler to contacts tab in the iPhone. I hope I could explain my problem.

My source code I hope it helps Download Link

Upvotes: 1

Views: 63

Answers (2)

Rob Napier
Rob Napier

Reputation: 299355

Use a document-based app (UIDocument). Give each user his own document. Switch between documents when you switch users. See Document-Based App Programming Guide for iOS.

Upvotes: 0

beryllium
beryllium

Reputation: 29767

This answer hasn't common answer without knowing your architecture and data which you show in table. Generally database greatly solve this problem - you store all data in db and fetch by predicate only needed data -

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name== %@", userName];
NSArray *orders = [Order findAllUsingPredicate:predicate]; // this is prototype method

But database is being used for large amount of data, and if you don't want to use db or have static data to display then look at plists. You can create plist with nodes

-John
  -Order1,Order2
-Mike
  -Order3,Order4,Order5
...

Then read this file, and fetch John's object like this:

NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:pathToPlist];
johnsObjects = [dict objectForKey:@"John"];

Hope, it will be helpful for you

Upvotes: 1

Related Questions