Created
September 8, 2011 10:39
-
-
Save rhysforyou/1203112 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void)addEvent | |
| { | |
| CLLocation *location = [locationManager location]; | |
| if (!location) { | |
| return; | |
| } | |
| Event *event = (Event *)[NSEntityDescription insertNewObjectForEntityForName:@"Event" | |
| inManagedObjectContext:managedObjectContext]; | |
| CLLocationCoordinate2D coordinate = [location coordinate]; | |
| [event setLatitude:[NSNumber numberWithDouble:coordinate.latitude]]; | |
| [event setLongitiude:[NSNumber numberWithDouble:coordinate.longitude]]; | |
| [event setCreationDate:[NSDate date]]; | |
| NSError *error = nil; | |
| if (![managedObjectContext save:&error]) { | |
| // Handle the 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]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment