So you want to pull out the data that is in your core data on a view?
first how is your data stores? Entity name? Attribute lists etc (dont need it all but i am struggling to decipher from your post)
Second, how are you passing your data to the next view? By this i mean how is "byTheHusk" defined in both locations? (also here i would advise not naming them the same as it will cause confusion when reviewing the code in a few months)
Third, how are you wanting to display the data?
A quick run over of how to get it done. This is based on being in a tableview on view 1.
So in view 2 you need a property, this property needs to belong to the Entity you are accessing - you should have classes in your project that are "NSManagedObject"'s (i.e. i have "StoreCustomers" as an entity, i also have a class created from that entity called "StoreCustomers".
so now in view 2 i have a property: "StoreCustomers *storeCustomers". If i go back to view 1 we now need to pass some data to that property. So in the didSelectRowForIndex we create our instance of the new viewcontroller (exactly like you did) but different from your implementation we just need to say that:
Code:
ViewTwo *viewTwo = [[viewtwo alloc] init...];
Entity *theEntity = (Entity *) the selected row;
viewTwo.storeCustomers = theEntity //the property from view 2 = the selected row from view 1
Now what we are doing here (this may not be 100% accurate but along these lines) is saying that the property in view 2 is the row form our core data that we have been looking at - we are passing the managedObject of that particular entry into core data to the next view.
So now if you nslogged the property in view 2 you would find that there is a nice list containing all the information that you want (or a reference to the row that you are looking for). And all we have left is the need to pull out all the little bits of data that we need.
So in view 2 we need a way of telling the log or the cellForRowAtIndex or the label to be the specific item of data for that row in core data.
Now if you remember our property in view 2 is actually created from a class that holds all of the attributes for that entity - and those are all properties that we can access from other classes. that is done like this:
Code:
UIElement = property.attributeProperty
so in my case of the customers example:
Code:
cell.detailTextLabel.text = storeCustomer.cuName
And that will then populate that cell with the name of the customer - and can be repeated in each cell for the other attributes i.e. phone number etc.
No worries, take your time looking it over, better to understand fully
Quote:
Quote:
By this i mean how is "byTheHusk" defined in both locations?
if i understand the question, there are definition files called ByTheHusk.h/m and all the files required are bing imported in the .m controllers
What i meant here was what is the object "byTheHusk". In the .h is it like this:
Code:
ByTheHusk *byTheHusk.....
or
NSArray *byTheHusk
From the sounds of it you have it right with ByTheHusk, that from your fetch looks like the Entity that you are accessing the top of that .h file should be like this:
Where "StoreAllCustomers" is the Entity
NSManagedObject is the class type
@property.... is the attribute from the entity (obviously there are more of these - 1 per attribute but i couldnt be bothered to copy them all :P)
That Class is possibly the most important in what you are trying to do as it is what sets up the interface for the store. It contains all the getters and setters to pull out the data from the store and allow you to use it.
Am I right in that the entire data blob is being passed, and if so I still need a control structure in a
Code:
for
or
Code:
while
again sorry I havent really gone over your code response yet (which you likely told me how to iterate), I want to make sure that the initial answer you gave me reflects the information I am providing. I will look at it now!!!
OK so simply put - forget the idea of iterating over it, forget for/while loops. None of those are needed to access ONE row of your core data. Once you have the object reference in your property then you just need to access the values on that.
f you had the data in an array at this point then you would need to iterate it, but you dont, you have the data stored to a property that can access it all with simple . notation:
but what is passed is the entire data set. so excuse my lack of knowledge here, what I would need to be able to do is:
Code:
NSLog(@"%@", byTheHusk.entryAtIndex:0.name);
or soemthing to that effect.
all the entries are being passed, which is what I want, but in the viewcontroller, I want to display a list of all the names (not in a table view)
Does that make sense?
Code:
bo
So you want to pass all the names of your Entity to a viewController that does not use a tableView, correct? For the row you select, that row contains something that can equate to a list that contains many names, correct? for example:
This example would have Two Entities RootView with TableView
Friends of Mine
Enemies of Mine
People I know
Touching on one of the above lists presents a new view (lets say Friends). DetailView without a TableView
Wayne
Steve
Jarrod
etc...
Is this what you want, or is your RootView setup where it contains ONE list with all names?
This would have One Entity
Wayne
Steve
Jarrod
etc...
You touch a name and on the next view you see that name.
Let us know what type of model you have and we can help get you to the result faster.
I want to parse the data in teh new viewcontroller
it is not in a table view or in a view where an index is passed or a single object.
bo
You are initializing nextViewController (I'm assuming this is a property you have defined in your .h file) with the xib file AfrianSwallowView. You are then using a NEW viewController (InstructionsViewController) to define nextViewController (I'm not sure why you're using parentheses around ((InstructionsViewController *)nextViewController) this part either).
However, you have already alloc init nextViewController in the line above and are then taking nextViewController and saying InstructionsViewController * has an IV named nextViewController.
What are you trying to do with the code you supplied? Are you wanting to load nextViewController, then you want to have a new viewController named InstructionsViewController display your managedObject?
in php terms (its what i am familiar with), in the view i am passing 'byTheHusk' to, I want to then do this:
Code:
foreach ($key as $item) {
echo "Name: ".$item['name'];// this would be a UILabel in xcode
}
I need to access all the data in the new view but not edit or delete, just iterate through and display.
I want to pass the 'byTheHusk' complete data object to the new view for parsing, but I dont know how to parse it. I have gotten to the point (I think) where the data blob is passed, I (think) I just need to equivalent to the for loop structure to set variables or I can even do it manually
those are the memory pointers, just telling me the address of what i am messing with - nothing to worry about in terms of what we are trying to get going here.
Ok so Tripp13 had the right idea, could you tell us which of the two data models that he posted best represent what you have?
So are you saying that you are passing your entire Core Data store for that entity to the next view? If that is the case then honestly i would change tack and do a new fetch in the new view - then use the array to populate your UIElements.
So my CustomersView must display the names of each customer from one entity in one table view. It could also display any other data, but i have a tableview and only want the name - if i wanted with a simple change i could turn it into labels and have them display any of the data from that customer at a given index. So once you have the fetch set up and all of that data in an array it is a fairly simple set of code. This is done because a managed object (as far as i know) wont respond to "objectAtIndex" whereas an array will.
To do this you must set up an instance from the moc (managedObjectContext) ad assign it an index path from the array something like this:
Now my theory is that once you are on view 2 - where you think you have the data set you should be able to set it into an array - the same as you would at the bottom of a fetch request:
Code:
[self setStoreHuskArray: mutableFetchResults];
Remember that in the above example the array would be this:
So you want to pass all the names of your Entity to a viewController that does not use a tableView, correct? For the row you select, that row contains something that can equate to a list that contains many names, correct?
what I am trying to do specifically, is pass the core data to a map view, so I can use the fields latitude and longitude to load the map points.
I want top pass the values to this map view so I can place all the pins
I'm at work right now and can't fully go through this right now, but I'll be home around 5 PM (1700) today Eastern timezone of the United States, about 4 hours from now.
A quick run through would be this:
-You have ViewController1 *vc1 and you want to push data from vc1 to ViewController2 *vc2.
-In vc1, you want to alloc init vc1 from the method you want the action to occur, i.e. didSelectRowAtIndexPath, (IBAction)buttonTouchid)sender, etc.
-You do the above like so (I'm just going to use an IBAction since I don't have the didSelectRow method line memorized. Either way, it's essentially the same):
Code:
- (IBAction)buttonTouch:(id)sender
{
// Make sure vc2 is imported into the .m file here
ViewController2 *vc2Pushed = [[ViewController2 alloc] init];
// With the init portion, you have a variety of options...choose what you want
[self.navigationController pushViewController:vc2Pushed animated:YES];
}
-Get this down first. Make sure you are pushing the viewController you want and that it is actually pushing the viewController. Also, make sure your viewControllers do have a navigationController.
- I'll get back in a few hours to add a bit more. Try this first and see if you are actually pushing the viewController.