Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Custom annotation/callout button no action

Hey, I am new to iPhone development and am having trouble assigning a action to a custom annotation. I want to have multiple annotations/callouts with buttons to show different information in a Detail View. The pins show with the buttons but don't do anything. Here is the code I have:

mapkitDemoAppDelegate.h
@interface mapkitDemoAppDelegate : NSObject <UIApplicationDelegate> {

UIWindow *window;
UITabBarController *navigationController;
IBOutlet UITabBarController* myTabBarController;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *navigationController;

@end


mapkitDemoAppDelegate.m

#import \"mapkitDemoAppDelegate.h\"



@implementation mapkitDemoAppDelegate

@synthesize window;
@synthesize navigationController;


#pragma mark -
#pragma mark Application lifecycle

- (void)applicationDidFinishLaunching:(UIApplication *)application {

// Override point for customization after app launch

[window addSubview:[myTabBarController view]];
[window makeKeyAndVisible];

}


- (void)applicationWillTerminate:(UIApplication *)application {
// Save data if appropriate
}


#pragma mark -
#pragma mark Memory management

- (void)dealloc {
[navigationController release];
[window release];
[super dealloc];
}

@end


mapViewController.h

#import \"mapkitDemoAppDelegate.h\"


@implementation mapkitDemoAppDelegate

@synthesize window;
@synthesize navigationController;


#pragma mark -
#pragma mark Application lifecycle

- (void)applicationDidFinishLaunching:(UIApplication *)application {

// Override point for customization after app launch

[window addSubview:[myTabBarController view]];
[window makeKeyAndVisible];

}


- (void)applicationWillTerminate:(UIApplication *)application {
// Save data if appropriate
}


#pragma mark -
#pragma mark Memory management

- (void)dealloc {
[navigationController release];
[window release];
[super dealloc];
}


@end



mapViewController.m


#import \"mapViewController.h\"
#import \"mapkitDemoAppDelegate.h\"
#import <CoreLocation/CoreLocation.h>


@implementation GPSAnnotation

@synthesize coordinate;
@synthesize mTitle;
@synthesize mSubTitle;
@synthesize currentPoint;
- (NSString *)subtitle{
return mSubTitle;
}
- (NSString *)title{
return mTitle;
}


-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
coordinate=c;
NSLog(@\"%f,%f\",c.latitude,c.longitude);
return self;
}

@end


@implementation mapViewController
@synthesize showDetailView;


/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/

/*
// 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 {
[super viewDidLoad];
mapView=[[MKMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
mapView.showsUserLocation=TRUE;
mapView.mapType=MKMapTypeSatellite;
mapView.delegate=self;

MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.00399;
span.longitudeDelta=0.00399;

CLLocationManager *locationManager=[[CLLocationManager alloc] init];
locationManager.delegate=self;
locationManager.desiredAccuracy=kCLLocationAccuracyBest; //kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];

CLLocationCoordinate2D location2 = mapView.userLocation.coordinate;

location2.latitude= 53.7905;
location2.longitude= -3.0557;
region.span=span;
region.center=location2;
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];


[self.view insertSubview:mapView atIndex:0];

CLLocationCoordinate2D c;
NSString *latitude = @\"<latitude>\";
NSString *longitude = @\"<longitude>\";
c.latitude = [latitude doubleValue];
c.longitude = [longitude doubleValue];
GPSAnnotation *annotation = [[GPSAnnotation alloc] initWithCoordinate:c];
annotation.currentPoint = [NSNumber numberWithInt:1];
annotation.mTitle=@\"Pin 1\";
annotation.mSubTitle = @\"...\";
[mapView addAnnotation:annotation];
[annotation release];

latitude = @\"<latitude>\";
longitude = @\"<longitude>\";
c.latitude = [latitude doubleValue];
c.longitude = [longitude doubleValue];
annotation = [[GPSAnnotation alloc] initWithCoordinate:c];
annotation.currentPoint = [NSNumber numberWithInt:2];
annotation.mTitle=@\"Pin 2\";
annotation.mSubTitle = @\"...\";
[mapView addAnnotation:annotation];
[annotation release];

latitude = @\"<latitude>\";
longitude = @\"<longitude>\";
c.latitude = [latitude doubleValue];
c.longitude = [longitude doubleValue];
annotation = [[GPSAnnotation alloc] initWithCoordinate:c];
annotation.currentPoint = [NSNumber numberWithInt:2];
annotation.mTitle=@\"Pin 3\";
annotation.mSubTitle = @\"...\";
[mapView addAnnotation:annotation];
[annotation release];


}

# pragma mark Personalized annotation

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(GPSAnnotation *) annotation{
int postag = 0;

MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@\"currentloc\"];
annView.pinColor = MKPinAnnotationColorRed;
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeCustom];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

// Set the image for the button
[myDetailButton setImage:[UIImage imageNamed:@\"button_right.png\"] forState:UIControlStateNormal];
[myDetailButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside];

if ([[annotation title] isEqualToString:@\"Current Location\"]) {
postag = 99999;
} else {
postag = [annotation.currentPoint intValue];
}
myDetailButton.tag = postag;


// Set the button as the callout view
annView.rightCalloutAccessoryView = myDetailButton;

annView.animatesDrop=TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}

- (IBAction)showLinks:(id)sender
{
int nrButtonPressed = ((UIButton *)sender).tag;

if (nrButtonPressed < 99999) {
if (self.showDetailView == nil) {
detailView *tmpViewController = [[detailView alloc] initWithNibName:@\"detailView\" bundle:nil];
self.showDetailView = tmpViewController;
[tmpViewController release];
}
[self.navigationController pushViewController:self.showDetailView animated:YES];

if (nrButtonPressed == 1) {
[self.showDetailView.detailDescription setText:@\"Pin 1 - description\"];
self.showDetailView.title = @\"Pin 1\";
[self.showDetailView.detailHeight setText:@\"44 Inches/112cm\"];
[self.showDetailView.detailWristband setText:@\"Unlimited & Junior\"];
[self.showDetailView.detailImage setImage:[UIImage imageNamed:@\"imagename1.png\"]];
}
if (nrButtonPressed == 2) {
[self.showDetailView.detailDescription setText:@\"Pin 2 - description\"];
self.showDetailView.title = @\"Pin 2\";
[self.showDetailView.detailHeight setText:@\"52 Inches/132cm\"];
[self.showDetailView.detailWristband setText:@\"Unlimited & Junior\"];
[self.showDetailView.detailImage setImage:[UIImage imageNamed:@\"imagename2.png\"]];
}
if (nrButtonPressed == 3) {
[self.showDetailView.detailDescription setText:@\"Pin 3 - description\"];
self.showDetailView.title = @\"Pin 3\";
[self.showDetailView.detailHeight setText:@\"46 Inches/117cm\"];
[self.showDetailView.detailWristband setText:@\"Unlimited & Junior\"];
[self.showDetailView.detailImage setImage:[UIImage imageNamed:@\"imagename3.png\"]];
}

}
}
#pragma mark Navigation With GPS (must activate [locationManager startUpdatingLocation]; in viewDidLoad)

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{

location=newLocation.coordinate;
//One location is obtained.. just zoom to that location

MKCoordinateRegion region;
region.center=location;
//Set Zoom level using Span
MKCoordinateSpan span;
span.latitudeDelta=.005;
span.longitudeDelta=.005;
region.span=span;

[mapView setRegion:region animated:TRUE];
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;

[super viewDidUnload];
}

#pragma mark -
#pragma mark CLLocationManagerDelegate Methods

- (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.
}

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

- (void)dealloc {
[super dealloc];
}
*/
@end


Please help fix my problem and just to remind you, I am new at iPhone developing so I'm a little slow. Thank you.
Sign In or Register to comment.