0
NoteSomething
Michael Pan
13年9月2⽇日星期⼀一
Looks like
13年9月2⽇日星期⼀一
Additional frameworks used
• CoreData
• CoreLocation
• MapKit
13年9月2⽇日星期⼀一
Core Data
13年9月2⽇日星期⼀一
Create Class for NSManagedObject
@interface Record : NSManagedObject
@property (nonatomic, retain) NSDate * timeStamp;
@pr...
New project
13年9月2⽇日星期⼀一
Check Core Data
13年9月2⽇日星期⼀一
Storyboard
13年9月2⽇日星期⼀一
Classes
13年9月2⽇日星期⼀一
Collect all data
13年9月2⽇日星期⼀一
CoreLocation - DetailViewController
- (void)configureView
{
locationManager= [CLLocationManager new];
locationManager.dele...
Get data
- (IBAction)recordNote:(id)sender {
NSString * notes = self.noteField.text;
CGFloat latitude = self.currentLocati...
Save data
if ([self saveImage:UIImagePNGRepresentation(image) withPath:imagePath]) {
Record * record = [NSEntityDescriptio...
Show info
13年9月2⽇日星期⼀一
InfoViewController
#import <CoreLocation/CoreLocation.h>
@interface InfoViewController : UIViewController
@property NSStri...
InfoViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageView.image = self.image;
self.noteLabel.text = s...
MKAnnotationView
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:
(id<MKAnnotation>)annotation{
MKAnn...
Move Region
-(void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
CLLocationCoordinate2D coordination = se...
MasterViewController
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject ...
MasterViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqua...
Question
13年9月2⽇日星期⼀一
Upcoming SlideShare
Loading in...5
×

Note something

303

Published on

Published in: Technology, Art & Photos
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
303
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Note something"

  1. 1. NoteSomething Michael Pan 13年9月2⽇日星期⼀一
  2. 2. Looks like 13年9月2⽇日星期⼀一
  3. 3. Additional frameworks used • CoreData • CoreLocation • MapKit 13年9月2⽇日星期⼀一
  4. 4. Core Data 13年9月2⽇日星期⼀一
  5. 5. Create Class for NSManagedObject @interface Record : NSManagedObject @property (nonatomic, retain) NSDate * timeStamp; @property (nonatomic, retain) NSString * notes; @property (nonatomic, retain) NSNumber * latitude; @property (nonatomic, retain) NSNumber * longitude; @property (nonatomic, retain) NSString * imagePath; @end 13年9月2⽇日星期⼀一
  6. 6. New project 13年9月2⽇日星期⼀一
  7. 7. Check Core Data 13年9月2⽇日星期⼀一
  8. 8. Storyboard 13年9月2⽇日星期⼀一
  9. 9. Classes 13年9月2⽇日星期⼀一
  10. 10. Collect all data 13年9月2⽇日星期⼀一
  11. 11. CoreLocation - DetailViewController - (void)configureView { locationManager= [CLLocationManager new]; locationManager.delegate = self; [locationManager startUpdatingLocation]; } -(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ self.currentLocation = [ (CLLocation *) [locations lastObject] coordinate]; } 13年9月2⽇日星期⼀一
  12. 12. Get data - (IBAction)recordNote:(id)sender { NSString * notes = self.noteField.text; CGFloat latitude = self.currentLocation.latitude; CGFloat longitude = self.currentLocation.longitude; UIImage * image = self.imageView.image; NSDate * date = [NSDate date]; NSString * fileName = [NSString stringWithFormat:@"%@",date]; NSString * imagePath = [[self docPath] stringByAppendingPathComponent:fileName]; if (image == nil) { NSLog(@"No image..."); return; } // save to data base } 13年9月2⽇日星期⼀一
  13. 13. Save data if ([self saveImage:UIImagePNGRepresentation(image) withPath:imagePath]) { Record * record = [NSEntityDescription insertNewObjectForEntityForName:@"Record" inManagedObjectContext:self.manangedContext]; record.notes = notes; record.latitude = @(latitude); record.longitude = @(longitude); record.imagePath = fileName; record.timeStamp = date; [self.manangedContext save:NULL]; } -(BOOL) saveImage:(NSData *) imageData withPath:(NSString *) filePath{ return [[NSFileManager defaultManager] createFileAtPath:filePath contents:imageData attributes:nil]; } 13年9月2⽇日星期⼀一
  14. 14. Show info 13年9月2⽇日星期⼀一
  15. 15. InfoViewController #import <CoreLocation/CoreLocation.h> @interface InfoViewController : UIViewController @property NSString * notes; @property UIImage * image; @property CLLocationCoordinate2D position; @end 13年9月2⽇日星期⼀一
  16. 16. InfoViewController.m - (void)viewDidLoad { [super viewDidLoad]; self.imageView.image = self.image; self.noteLabel.text = self.notes; self.mapView.delegate = self; MyAnnotation * annotation = [MyAnnotation new]; annotation.coordinate = self.position; [self.mapView addAnnotation:annotation]; } 13年9月2⽇日星期⼀一
  17. 17. MKAnnotationView -(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation: (id<MKAnnotation>)annotation{ MKAnnotationView * annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"POI"]; if (annotationView == nil) { annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"POI"]; MKPinAnnotationView * pinView = annotationView; pinView.pinColor = MKPinAnnotationColorPurple; } return annotationView; } 13年9月2⽇日星期⼀一
  18. 18. Move Region -(void) viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; CLLocationCoordinate2D coordination = self.position; MKCoordinateSpan mySpan = {0.05f, 0.05f}; MKCoordinateRegion toRegion = {coordination, mySpan}; [self.mapView setRegion:toRegion animated:YES]; } 13年9月2⽇日星期⼀一
  19. 19. MasterViewController - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath { NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath]; cell.textLabel.text = [[object valueForKey:@"notes"] description]; cell.detailTextLabel.text = [[object valueForKey:@"timeStamp"] description]; NSString * imagePath = [object valueForKey:@"imagePath"]; UIImage * image = [UIImage imageWithContentsOfFile:[[self docPath] stringByAppendingPathComponent:imagePath]]; cell.imageView.image = image; } 13年9月2⽇日星期⼀一
  20. 20. MasterViewController.m - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"record"]) { DetailViewController * detailViewController = segue.destinationViewController; detailViewController.manangedContext = self.managedObjectContext; } if ([segue.identifier isEqualToString:@"showInfo"]) { NSIndexPath * indexPath = [self.tableView indexPathForSelectedRow]; Record * record = [self.fetchedResultsController objectAtIndexPath:indexPath]; InfoViewController * info = segue.destinationViewController; info.notes = record.notes; info.position = CLLocationCoordinate2DMake([record.latitude doubleValue], [record.longitude doubleValue]); info.image = [UIImage imageWithContentsOfFile:[[self docPath] stringByAppendingPathComponent:record.imagePath]]; } } 13年9月2⽇日星期⼀一
  21. 21. Question 13年9月2⽇日星期⼀一
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×