Note that there are some explanatory texts on larger screens.

plurals
  1. POSimulator not getting location
    primarykey
    data
    text
    <p>I'm following <a href="http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/iPhoneCoreData01/Articles/02_RootViewController.html" rel="nofollow">this tutorial</a> to learn about Core Data. I'm currently on section 4, Adding Events. In section 2 the tutorial says that the Add Button will become active seconds after I am prompted by the Simulator to get my location, but it never becomes active, any idea what might be happening?</p> <p>PS: If I hardcode the button to be active before getting location I get the following error:</p> <pre><code>*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array' </code></pre> <p>On the following line:</p> <pre><code>[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; </code></pre> <p>EDIT: Posting more code to get a bigger picture</p> <pre><code>- (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]; } </code></pre> <p>This is the method where I get there error:</p> <pre><code>-(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:&amp;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]; } </code></pre> <p>And my appDidLaunch method:</p> <pre><code>- (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; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload