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-06-2012, 10:29 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default MapView Annotation Callout Help

I have a mapview setup with multiple annotations. I have the annotations added to a Mutable Array, and everything shows up fine in the view. My questions is how do I get the proper view to popup when selecting the callout for each annotation. I found the following off a tutorial online, but not for sure on the DetailView what type of object to setup, nor how to do it. My MutableArray is called annotations. Here is the code I have:
Code:
-(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];
        
        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 {
    NSInteger selectedIndex = sender.tag;
    MKAnnotationView *selectedObject = [self.annotations objectAtIndex:selectedIndex];
    
          self.detailView = [[[DetailView alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]] autorelease];    
    _detailView.detailObject = selectedObject;

    [[self navigationController] pushViewController:_detailView animated:YES];
     
}
_detailView has nothing declared in properties, so I get the error that property detailObject is not found on object of type DetailView. How do I set this up properly to show a certain view when the selected annotation is clicked.
__________________
My latest app...i Miss Mommy
spiderguy84 is offline   Reply With Quote
Old 02-06-2012, 10:57 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 920
spiderguy84 is on a distinguished road
Default

I tried some different tutorials online and changed my code on the ibaction to this:
Code:
-(IBAction)showDetailView:(UIView*)sender {
    NSInteger selectedIndex = sender.tag;
    
    DetailView *nextController = [[DetailView alloc] initWithNibName:@"DetailView" bundle:nil];
    [self presentModalViewController:nextController animated:YES];
    [nextController changeProductText:[self.annotations objectAtIndex:selectedIndex]]; 
     
}
In the DetailView I added the IBAction
Code:
 - (IBAction) changeProductText:(NSString *)str
and in the implementation added
Code:
- (IBAction) changeProductText:(NSString *)str{
    NSLog(@"%@", str);
}
The log returns the str as
Code:
<DisplayMap: 0x877d170>
I thought that maybe I could just create a few If statements comparing str to what the NSLog had returned for each annotation. However,
Code:
<DisplayMap: 0x877d170>
is a different value each time I run the application. Thoughts?
__________________
My latest app...i Miss Mommy
spiderguy84 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: 400
18 members and 382 guests
Alex-alex, Apptronics RBC, Atatator, chiataytuday, dre, FrankWeller, gwelmarten, ipodphone, jeroenkeij, jleannex55, LunarMoon, MAMN84, n00b, pbart, reficul, Retouchable, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,124
Posts: 402,909
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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