Я следую this tutorial, чтобы узнать о Core Data. Я сейчас в разделе 4 «Добавление событий». В разделе 2 в учебнике говорится, что кнопка «Добавить» станет активной секундой после того, как я попрошу симулятор получить мое местоположение, но он никогда не становится активным, любая идея, что может произойти?Симулятор не получает местоположение
PS: Если я жёстко кнопку, чтобы быть активным перед тем, как местоположение, я получаю следующее сообщение об ошибке:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
На следующей строке:
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
EDIT: Проводка больше кода, чтобы получить большая картина
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Locations";
self.navigationItem.leftBarButtonItem = self.editButtonItem;
addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addEvent)];
addButton.enabled = NO;
self.navigationItem.rightBarButtonItem = self.addButton;
[[self locationManager] startUpdatingLocation];
eventsArray = [[NSMutableArray alloc] init];
}
Это метод, где я получаю там ошибку:
-(void)addEvent{
CLLocation *location = [locationManager location];
if(location){
return;
}
Event *event = (Event *)[NSEntityDescription insertNewObjectForEntityForName:@"Event" inManagedObjectContext:managedObjectContext];
CLLocationCoordinate2D coordinate = [location coordinate];
event.latitude = [NSNumber numberWithFloat:coordinate.latitude];
event.longitude = [NSNumber numberWithFloat:coordinate.longitude];
event.creationDate = [NSDate date];
NSError *error;
if (![managedObjectContext save:&error]) {
}
[eventsArray insertObject:event atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
И мой метод appDidLaunch:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
navigationController = [[UINavigationController alloc] init];
NSManagedObjectContext *context = [self managedObjectContext];
if(!context){
}
rootViewController.managedObjectContext = context;
[self.navigationController pushViewController:rootViewController animated:NO];
[rootViewController release];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
Я обновил свой код с помощью других соответствующих методов в своем представленииDidLoad, где я выделяю NSMutableArray, который является свойством моего RootViewController – 8vius