Alpinista
Alpinista

Reputation: 3741

Using CoreData outside of a TableView on the iPhone

My application has a simple data model with 70 read-only records grouped into six categories. Currently the persistent data is stored in an XML file which I parse on application launch, and create objects for each record which are stored in an NSMutableArray.

I then populate a UIPickerView from the objects stored in the array, and when the user selects a row in the picker, display content pulled from the same objects.

Using CoreData and SQLite would use much less code, but it seems to be designed to work with UITableViews exclusively.

Has anyone used CoreData to fetch records outside of the UITableView interface?

Thanks

jk

Upvotes: 0

Views: 510

Answers (2)

Alex Reynolds
Alex Reynolds

Reputation: 96994

I put my custom Core Data methods into the application delegate, where they can be called from any class. To do this, I add a #define as follows:

#define UIAppDelegate ((MyAppDelegate *) [[UIApplication sharedApplication] delegate])

I can then call my methods like so:

[UIAppDelegate fetchBooks:managedObjectContext];

A UITableView is not required for any of this.

Upvotes: 0

ck.
ck.

Reputation: 327

Core Data is not designed to work with UITableViews only. Although it's really easy to Core Data with the NSFetchedResultsController to populate a table view you can still do all the fetches you want on your an.

Just make your own NSFetchRequests to get the data you want. From the list of objects, particular objects or just single values you can use this date for whatever purpose intended.

Upvotes: 3

Related Questions