在我已注释掉的几行中出现此错误,想知道为什么会出现此问题?解决此问题的最佳方法是什么?
Location 是一个 CoreData 实体,placemark 是它的属性之一。
提前致谢。
LocationsViewController.m
#import "LocationsViewController.h"
#import "Location.h"
@interface LocationsViewController ()
@end
@implementation LocationsViewController{
NSArray *locations;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Location" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
NSError *error;
NSArray *foundObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
if (foundObjects == nil) {
FATAL_CORE_DATA_ERROR(error);
return;
}
locations = foundObjects;
}
- (void)viewDidUnload
{
[super viewDidUnload];
locations = nil;
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [locations count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Location"];
UILabel *descriptionLabel = (UILabel *) [cell viewWithTag:100];
descriptionLabel.text = @"If you can see this";
UILabel *addressLabel = (UILabel *)[cell viewWithTag:101];
addressLabel.text = @"%@ %@, %@",
location.placemark.subThoroughfare, // Use of undeclared identifier 'location'
location.placemark.thoroughfare, // Use of undeclared identifier 'location'
location.placemark.locality ]; // Use of undeclared identifier 'location'
return cell;
}
@end