Reputation: 34629
I'm new to iOS, Objective-C and have only done a small ammount of OO programming before but enjoying the challenge of trying to create this app.
Summary of app: I have a view which is just a form to enter information into the Core Data database eg. Name, Address & Telephone. Then another view which contains a Table View which lists all the names of people currently in database.
However this is where i'm stuck...
I have created a detailed view so that when a user selects a Table Cell the detailed view loads but i want to get data from Core Data back into the form they used to originally enter the data so it can be modified/editted and re-saved back to Core Data.
What are the best practicies of doing this?
I will need to pass some data forward to the detailed view, which know how to do, but what should I pass? how do I tell the detailed view which row of data in the Core Data database I wish to load?
Do I pass the tableview indexPath.row value? does this correspond to anything I can filter down in CoreData when loading the detailed view?
Thanks in advance to anyone who replies, would appreciate any help from methodology to online tuts
Matt
Upvotes: 0
Views: 340
Reputation: 34629
Picking out bits from CoreRecipes sample code as suggested by TheRonin I did the following.
Create an iVar of Core-Data DataModel object on the DetailedViewController
DataStore *enquiry;
On the tableview view under didSelectRowAtIndex setup Core-Data DataModel object and Detailed view controller,
DataStore *enquiry = (DataStore *)[_fetchedResultsController objectAtIndexPath:indexPath];
ShowEnquiryDetail *detailViewController = [[ShowEnquiryDetail alloc] initWithNibName:@"ShowEnquiryDetail" bundle:nil ];
set the Data Model object in DetailedViewController
detailViewController.enquiry = enquiry;
then push the DetailedViewController on to navigation stack.
[self.navigationController pushViewController:detailViewController animated:YES];
Then on the DetailedViewController you can access the data in the DataModel object from the selected row in Core-Data using enquiry.name, enquiry.email, etc...
This isn't a well written answer and may use incorrect terminology but hopefully it will help someone in the same position I was.
Upvotes: 0
Reputation: 1315
I think you can see Apple sample code here : CoreRecipes sample code
Upvotes: 1