使用未声明的标识符“位置”

时间:2013-01-30 18:57:59

标签: objective-c core-data

我已经注释掉了几行这个错误,并想知道为什么我会遇到这个问题?解决这个问题的最佳方法是什么?

位置是CoreData实体,地标是其属性之一。

提前致谢。

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

1 个答案:

答案 0 :(得分:1)

cellForRowAtIndexPath

你忘记了

Location *location = locations[indexPath.row];
相关问题