Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-09-2012, 05:25 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default Map Callout Only on Some Annotations

I am trying to set up my MapView so that only some of the Pin Views will show CallOut Button. for my map view controller Maps.h I have:
Code:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@class DetailView;
@interface Maps : UIViewController <MKMapViewDelegate> {
    DetailView *_detailView;
    IBOutlet MKMapView *mapView;
    NSMutableArray *annotations;
}
@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@property (nonatomic, retain) NSMutableArray *annotations;
@property (retain) DetailView *detailView;
@end
The Maps.m
Code:
#import "Maps.h"
#import "DisplayMap.h"
#import "DetailView.h"
@implementation Maps
@synthesize annotations;
@synthesize detailView = _detailView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

    }
    return self;
}

- (void)didReceiveMemoryWarning
{

    [super didReceiveMemoryWarning];
    

}

#pragma mark - View lifecycle


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [mapView setMapType:MKMapTypeSatellite];
    [mapView setZoomEnabled:YES];
    [mapView setScrollEnabled:YES];
    mapView.delegate = self;
    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
    region.center.latitude = 32.385325 ;
    region.center.longitude = -86.217442;
    region.span.longitudeDelta = 0.005f;
    region.span.latitudeDelta = 0.005f;
    [mapView setRegion:region animated:YES];
    CLLocationCoordinate2D theCoordinate;
    self.annotations=[[NSMutableArray alloc] init];
    //the first annotation
    theCoordinate.latitude = 32.388152;
    theCoordinate.longitude = -86.216948;
    CLLocationCoordinate2D law;
    
    //the first annotation
    law.latitude = 32.383024;
    law.longitude = -86.214974;

    CLLocationCoordinate2D rotunda;
    
    //the first annotation
    rotunda.latitude = 32.384129;
    rotunda.longitude = -86.216476;
    
    CLLocationCoordinate2D margaret;
    
    //the first annotation
    margaret.latitude = 32.382363;
    margaret.longitude = -86.220682;
    
   


    [mapView setDelegate:self];
    
    DisplayMap *ann = [[DisplayMap alloc] init];
    ann.title = @"Tennis Courts";
    ann.subtitle = @"";
    ann.coordinate = region.center;
    [mapView addAnnotation:ann];
    DisplayMap *ann1 = [[DisplayMap alloc] init];
    ann1.title = @"Harrison Field";
    ann1.subtitle = @"Baseball";
    ann1.coordinate = theCoordinate;
    [mapView addAnnotation:ann1];
    DisplayMap *ann2 = [[DisplayMap alloc] init];
    ann2.title = @"Thomas Goode Jones School of Law";
    ann2.subtitle = @"Marjorie Snook Building";
    ann2.coordinate = law;
    [mapView addAnnotation:ann2];
    DisplayMap *ann3 = [[DisplayMap alloc] init];
    ann3.title = @"E.L. Collum Rotunda";
    ann3.subtitle = @"";
    ann3.coordinate = rotunda;
    [mapView addAnnotation:ann3];
    DisplayMap *ann4 = [[DisplayMap alloc] init];
    ann4.title = @"Margaret Harris";
    ann4.subtitle = @"Women's Residence Hall";
    ann4.coordinate = margaret;
    [mapView addAnnotation:ann4];
  
        [annotations addObject:ann3];
	[annotations addObject:ann4];
    [annotations addObject:ann2];
	[annotations addObject:ann1];
	[annotations addObject:ann];
   
}

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
    MKPinAnnotationView *pinView = nil;
    if(annotation != mapView.userLocation)
    {
        static NSString *defaultPinID = @"com.invasivecode.pin";
        pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
                    pinView.pinColor = MKPinAnnotationColorRed;
            pinView.canShowCallout = YES;
            pinView.animatesDrop = YES;
            UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            [detailButton setTitle:annotation.title forState:UIControlStateNormal];
            NSInteger annotationValue = [self.annotations indexOfObject:annotation];
            
            detailButton.tag = annotationValue;
            
            [detailButton addTarget:self action:@selector(showDetailView:) forControlEvents:UIControlEventTouchUpInside];
            
            pinView.rightCalloutAccessoryView = detailButton;
            return pinView;

        
            }
    else {
        [mapView.userLocation setTitle:@"I am here"];
    }
    return pinView;
}
-(IBAction)showDetailView:(UIView*)sender {
    NSString *where = ((UIButton*)sender).currentTitle;
    
    DetailView *nextController = [[DetailView alloc] initWithNibName:@"DetailView" bundle:nil];
        

    [self presentModalViewController:nextController animated:YES];
    [nextController changeProductText:where]; 

     
}

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



@end
I have tried adding an NSString *callitem to the NSObject 'DisplayMaps' .h file, and then on the annotations, calling like this:
Code:
ann.callitem = @"LetCall";
and in the viewForAnnotation, changing to:
Code:
if (annotations.callitem isEqualToString:@"LetCall" {
...
}
However, I get the error Property for callitem not found on NSMutableArray.
Am I going about this the right way, or is there an easier (Or at least better way) to only allow some annotations to show callout?
__________________
My latest app...i Miss Mommy
spiderguy84 is offline   Reply With Quote
Old 02-10-2012, 11:38 AM   #2 (permalink)
Use [code] tags please
 
Join Date: Jun 2009
Location: Jacksonville, FL
Posts: 410
timle8n1 is on a distinguished road
Default

You are calling callitem on annotations which is your array not on annotation - which is the annotation to provide the view for. While you are guarding against the current location annotation you should probably make sure the annotation has the callitem method by checking for that selector or checking the class is your expected class.
timle8n1 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 390
10 members and 380 guests
chiataytuday, chits12345, fiftysixty, gmarro, KennyChong, kilobytedump, Leslie80, Meoz, ryantcb, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,670
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Yosh_K
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:27 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0