I am passing data to the view using this method:
nextViewController = [[AfricanSwallowViewCont开发者_C百科roller alloc] initWithNibName:@"AfricanSwallowView" bundle:nil];
((InstructionsViewController *)nextViewController).byTheHusk = byTheHusk;
I am trying to iterate over the values on the view that byTheHusk gets passed to.
I have tried several versions of NSLog(@"%@", byTheHusk.name);
and using objectAtIndexPath
etc. with no luck
Is there a way to access the the objects entries attributes in a while
or for
loop style structure?
The closest I can get is:
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:0];
NSLog(@"%@",[[managedObject valueForKey:@"name"] description]);
which results in:
ByTheHusk[7880:207] (null)
Which means there are 207 entries. Is that right? and that ByTheHusk is getting passed correctly?
I am a noob to this all so thanks for any help!!!
Bo
I think you are confusing a NSManagedObjectContext object with a NSManagedObject object.
This code segment:
nextViewController = [[AfricanSwallowViewController alloc] initWithNibName:@"AfricanSwallowView" bundle:nil];
((InstructionsViewController *)nextViewController).byTheHusk = byTheHusk;
... looks like an attempt to hand of a NSManagedObjectContext from one view controller to another. However, the attempted cast is probably throwing things off. It should probablylook like this:
InstructionsViewController *nextViewController = [[AfricanSwallowViewController alloc] initWithNibName:@"AfricanSwallowView" bundle:nil];
nextViewController.byTheHusk = self.byTheHusk; //assuming that byTheHusk is a property of the current view controller.
I'm guessing that InstructionsViewController
is a tableview controller using a NSFetchedResultsController and configured to fetch from the byTheHusk
managed object context.
If so, then getting a null
return from this code:
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:0];
NSLog(@"%@",[[managedObject valueForKey:@"name"] description]);
... probably indicates that the fetchedResultsController
finds no objects when it fetches. In any case, it would not log the byTheHusk
object but just the first NSManagedObject instance that the fetch found.
ByTheHusk[7880:207] (null)
Which means there are 207 entries. Is that right? and that ByTheHusk is getting passed correctly?
No. In this case ByTheHusk
is the name of the app/library and the numbers are IIRC the line and block offsets in the object file. They have nothing to do with object being logged. The (null)
simply means that the statement [[managedObject valueForKey:@"name"] description]
does not return an object of any kind.
Not sure what your problem is but fixing the first bit of code above will help.
I figured it out through some eduction and trial and error and error and error.
But I got it!!!!
NSMutableArray* annotations=[[NSMutableArray alloc] init];
// Save our fetched data to an array
[self setEventArray: mutableFetchResults];
[mutableFetchResults release];
[request release];
//NSLog(@"%d",[eventArray count]);
for (int i = 0; i < [eventArray count]; i++) {
//NSLog(@"%@",[[eventArray objectAtIndex:i] name]);
CLLocationCoordinate2D theCoordinate;
double latNum = [[[eventArray objectAtIndex:i] latitude] doubleValue];
theCoordinate.latitude = latNum;
double lonNum = [[[eventArray objectAtIndex:i] longitude] doubleValue];
theCoordinate.longitude = lonNum;
//-------------------------
MyAnnotation* tempAnnotation=[[MyAnnotation alloc] init];
tempAnnotation.coordinate=theCoordinate;
tempAnnotation.title=[NSString stringWithFormat:@"%@",[[eventArray objectAtIndex:i] name]];
tempAnnotation.subtitle=[NSString stringWithFormat:@"%@",[[eventArray objectAtIndex:i] name]];
//-------------------------
[mapView addAnnotation:tempAnnotation];
[annotations addObject:tempAnnotation];
}
Put it in an array and roll over it... thanks all for the guidance!
精彩评论