Skip to content

Commit

Permalink
Added photos and location
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarden committed Sep 20, 2011
1 parent a587076 commit d96629e
Show file tree
Hide file tree
Showing 64 changed files with 9,104 additions and 64 deletions.
238 changes: 230 additions & 8 deletions LocationSample.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions LocationSample/DetailViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@
//

#import <UIKit/UIKit.h>
#import "Venue.h"

@interface DetailViewController : UIViewController

@property (strong, nonatomic) id detailItem;
@property (strong, nonatomic) Venue *venue;

@property (strong, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
@property (strong, nonatomic) IBOutlet UILabel *name;

@property (nonatomic, retain) IBOutlet UITextView *description;


- (IBAction)openMap:(id)sender;
- (IBAction)openPhotos:(id)sender;
@end
46 changes: 34 additions & 12 deletions LocationSample/DetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,33 @@
//

#import "DetailViewController.h"
#import "MapView.h"
#import "PhotosController.h"

@interface DetailViewController ()
- (void)configureView;
@end

@implementation DetailViewController

@synthesize detailItem = _detailItem;
@synthesize detailDescriptionLabel = _detailDescriptionLabel;
@synthesize venue = _venue;
@synthesize name = _name;
@synthesize description = _description;

- (void)dealloc
{
[_detailItem release];
[_detailDescriptionLabel release];
[_name release];
[_venue release];
[super dealloc];
}

#pragma mark - Managing the detail item

- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
[_detailItem release];
_detailItem = [newDetailItem retain];
if (_venue != newDetailItem) {
[_venue release];
_venue = [newDetailItem retain];

// Update the view.
[self configureView];
Expand All @@ -41,8 +44,9 @@ - (void)configureView
{
// Update the user interface for the detail item.

if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
if (self.venue) {
self.name.text = _venue.name;
self.description.text = _venue.description;
}
}

Expand Down Expand Up @@ -70,12 +74,14 @@ - (void)viewDidUnload

- (void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
self.navigationController.navigationBar.translucent = NO;
[super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
Expand All @@ -98,9 +104,25 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Detail", @"Detail");
self.title = _venue.name;
}
return self;
}


#pragma mark - IBActions
- (IBAction)openMap:(id)sender
{
MapView *map = [[MapView alloc] init];
map.venue = _venue;
[self.navigationController pushViewController:map animated:YES];
[map release];
}

- (IBAction)openPhotos:(id)sender
{
PhotosController *photos = [[PhotosController alloc] init];
photos.venue = _venue;
[self.navigationController pushViewController:photos animated:YES];
[photos release];
}
@end
17 changes: 17 additions & 0 deletions LocationSample/MapView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// MapView.h
// LocationSample
//
// Created by Daniel Barden on 9/20/11.
// Copyright (c) 2011 None. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "Venue.h"

@interface MapView : UIViewController <MKMapViewDelegate>

@property (nonatomic, retain) MKMapView *mapView;
@property (nonatomic, retain) Venue *venue;
@end
90 changes: 90 additions & 0 deletions LocationSample/MapView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// MapView.m
// LocationSample
//
// Created by Daniel Barden on 9/20/11.
// Copyright (c) 2011 None. All rights reserved.
//

#import "MapView.h"

@interface MyAnnotation : NSObject <MKAnnotation>
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@end

@implementation MyAnnotation
@synthesize coordinate = _coordinate;
@synthesize title = _title;

@end

@implementation MapView
@synthesize mapView = _mapView;
@synthesize venue = _venue;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
self.title = _venue.name;

_mapView = [[MKMapView alloc] initWithFrame:self.view.frame];
MKCoordinateRegion region;
region.center.latitude = _venue.location.coordinate.latitude;
region.center.longitude = _venue.location.coordinate.longitude;
region.span.latitudeDelta = 0.1;
region.span.longitudeDelta = 0.1;

MyAnnotation *annotation = [[MyAnnotation alloc] init];
annotation.coordinate = _venue.location.coordinate;
annotation.title = _venue.name;

[_mapView setRegion:region];
[_mapView addAnnotation:annotation];
[self.view addSubview:_mapView];

[super viewDidLoad];
}


- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
5 changes: 4 additions & 1 deletion LocationSample/MasterViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
//

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@class DetailViewController;

@interface MasterViewController : UITableViewController
@interface MasterViewController : UITableViewController <CLLocationManagerDelegate>

@property (strong, nonatomic) DetailViewController *detailViewController;
@property (nonatomic, retain) NSArray *venues;

@property (nonatomic, retain) CLLocationManager *clManager;
@end
45 changes: 42 additions & 3 deletions LocationSample/MasterViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
//

#import "MasterViewController.h"
#import <CoreLocation/CoreLocation.h>

#import "DetailViewController.h"
#import "Venue.h"

@implementation MasterViewController

@synthesize detailViewController = _detailViewController;
@synthesize venues = _venues;
@synthesize clManager = _clManager;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
Expand Down Expand Up @@ -40,7 +44,21 @@ - (void)didReceiveMemoryWarning
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

UIBarButtonItem *barbutton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(getLocation)];
self.navigationItem.rightBarButtonItem = barbutton;

_clManager = [[CLLocationManager alloc] init];
_clManager.delegate = self;

Venue *venue = [[Venue alloc] initWithName:@"Marinha" withLatitude:-30.05 withLongitude:-51.20];
venue.description = @"Este parque esta jogado as tracasasdajsdlkajsdlja asdasasad asdaksjdasd asdlkasjdasd asdlkasdas dasdk asldk asdasldkasdklsad asdkalf asklf dfsdlkfsdlfksd fsdklf sdfklsdfksdlfksdlfsdkfsdlkf sdlfksdlfksdklf sdlfkdsf dsflksdkf dsflsdkf sdlkflsdkflsdkflsdkf sdfklsdflksdflksdlfksdfsdlkf sklfsdfk sdlfsdklfsdkflskd fslkdf sdlkf sldkfklsdfdslfksdlfksdflksdf lskdf sldkflsdkfsdklfksdlfsdlkfsdlk fdslkfsldkflsdkflsdkfsdklf dlskf lsdkfsdlfskdflsdlfksdfsdlkf sdklfdslkfklsd flksd flksdkflsdfkldskfdslfkdslfkdsfldskfsdlfksdlfksdlf sdflk dsf";
NSArray *photos = [[NSArray alloc] initWithObjects:@"marinha1.jpg", @"marinha2.jpg", @"marinha3.jpg", nil];
venue.photos = photos;
[photos release];

NSArray *tmpVenues = [[NSArray alloc] initWithObjects:venue, nil];
self.venues = tmpVenues;
}

- (void)viewDidUnload
Expand Down Expand Up @@ -94,12 +112,14 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

// Configure the cell.
cell.textLabel.text = NSLocalizedString(@"Detail", @"Detail");
Venue *venue = [self.venues objectAtIndex:indexPath.row];
cell.textLabel.text = venue.name;
cell.detailTextLabel.text = venue.distance;
return cell;
}

Expand Down Expand Up @@ -146,7 +166,26 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
if (!self.detailViewController) {
self.detailViewController = [[[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil] autorelease];
}

self.detailViewController.venue = [_venues objectAtIndex:indexPath.row];
[self.navigationController pushViewController:self.detailViewController animated:YES];
}

#pragma mark - Location Methods
- (void)getLocation
{
if (! [CLLocationManager locationServicesEnabled])
return;

[_clManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
for (Venue *venue in _venues) {
[venue updateDistance:newLocation];
}
[_clManager stopUpdatingLocation];
[self.tableView reloadData];
}
@end
17 changes: 17 additions & 0 deletions LocationSample/PhotosController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// PhotosController.h
// LocationSample
//
// Created by Daniel Barden on 9/20/11.
// Copyright (c) 2011 None. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "NimbusPhotos.h"
#import "Venue.h"

@interface PhotosController : NIToolbarPhotoViewController <NIPhotoAlbumScrollViewDataSource, NIPhotoScrubberViewDataSource>

@property (nonatomic, retain) Venue *venue;
@property (nonatomic, retain) NIPhotoAlbumScrollView *photoview;
@end
Loading

0 comments on commit d96629e

Please sign in to comment.