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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 09-06-2010, 07:56 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 22
Default At my wit's end with MKMapView and delegates!

Well after 40 safari windows being open and realizing that most other forums are just scrapes from StackOverflow.com i've given up and come here after thinking i could figure this out myself.

my mkmapview doesn't call the delegate for this function:

Code:
- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id ) annotation {

i've made "File's Owner" the delegate and said gameMap.delegate = self; in the viewDidLoad functions. See below:

gameView.m
Code:
- (void)viewDidLoad {	
	...
	gameMap.delegate = self;
}

/*
 why is this function not being called by my delegate?!?!
 */
- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id ) annotation {
    MKAnnotationView *customAnnotationView=[[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
    UIImage *pinImage = [UIImage imageNamed:@"1.png"];
    [customAnnotationView setImage:pinImage];
    customAnnotationView.canShowCallout = YES;
    return customAnnotationView;
}
gameView.h
Code:
@interface GameView : UIViewController <MKMapViewDelegate>	{
	IBOutlet MKMapView *gameMap;
and in interface builder i have the mkmapview gameMap's delegate as file's owner.

please end my frustration i just want these damn pins to be the image "1.png"
meleader2 is offline   Reply With Quote
Old 09-06-2010, 08:27 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 4,814
Default

Quote:
Originally Posted by meleader2 View Post
Well after 40 safari windows being open and realizing that most other forums are just scrapes from StackOverflow.com i've given up and come here after thinking i could figure this out myself.

my mkmapview doesn't call the delegate for this function:

Code:
- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id ) annotation {

i've made "File's Owner" the delegate and said gameMap.delegate = self; in the viewDidLoad functions. See below:

gameView.m
Code:
- (void)viewDidLoad {	
	...
	gameMap.delegate = self;
}

/*
 why is this function not being called by my delegate?!?!
 */
- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id ) annotation {
    MKAnnotationView *customAnnotationView=[[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
    UIImage *pinImage = [UIImage imageNamed:@"1.png"];
    [customAnnotationView setImage:pinImage];
    customAnnotationView.canShowCallout = YES;
    return customAnnotationView;
}
gameView.h
Code:
@interface GameView : UIViewController <MKMapViewDelegate>	{
	IBOutlet MKMapView *gameMap;
and in interface builder i have the mkmapview gameMap's delegate as file's owner.

please end my frustration i just want these damn pins to be the image "1.png"
Usually this sort of thing is the result of a broken link in IB.

If you set a breakpoint in your viewDidLoad method, and examine the value of gameMap, is it nil? That would be my first guess.

Are your map view's other delegate methods getting called?
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-06-2010, 08:49 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 22
Default

thanks for the reply:

i set a breakpoint where you asked me to, i see it has an address and is not nil. Annotations draw as red pins, i can set region and span without a problem and the map updates my user location without an issue.

setting a breakpoint in that one delegate method though never ever gets hit.

i do not think i am implementing any other MKMapView delegate methods. I have an MKAnnotation delegate and a CCLocationManager delegate in other classes and i know that these are getting hit.

i've inspected IB and re-delegated to "File's Owner", it still did not fix the problem.
meleader2 is offline   Reply With Quote
Old 09-06-2010, 08:56 PM   #4 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 22
Default

Quote:
Originally Posted by meleader2 View Post
thanks for the reply:

i set a breakpoint where you asked me to, i see it has an address and is not nil. Annotations draw as red pins, i can set region and span without a problem and the map updates my user location without an issue.

setting a breakpoint in that one delegate method though never ever gets hit.

i do not think i am implementing any other MKMapView delegate methods. I have an MKAnnotation delegate and a CCLocationManager delegate in other classes and i know that these are getting hit.

i've inspected IB and re-delegated to "File's Owner", it still did not fix the problem.
i don't know if it would help to know the hierarchy in IB but it is:

File's Owner
First Responder
View -> View -> View -> Map View

and Map View's Outlet for delegate is "File's Owner"
meleader2 is offline   Reply With Quote
Old 09-06-2010, 09:03 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 4,814
Default

Quote:
Originally Posted by meleader2 View Post
Well after 40 safari windows being open and realizing that most other forums are just scrapes from StackOverflow.com i've given up and come here after thinking i could figure this out myself.

my mkmapview doesn't call the delegate for this function:

Code:
- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id ) annotation {

i've made "File's Owner" the delegate and said gameMap.delegate = self; in the viewDidLoad functions. See below:

gameView.m
Code:
- (void)viewDidLoad {	
	...
	gameMap.delegate = self;
}

/*
 why is this function not being called by my delegate?!?!
 */
- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id ) annotation {
    MKAnnotationView *customAnnotationView=[[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
    UIImage *pinImage = [UIImage imageNamed:@"1.png"];
    [customAnnotationView setImage:pinImage];
    customAnnotationView.canShowCallout = YES;
    return customAnnotationView;
}
gameView.h
Code:
@interface GameView : UIViewController <MKMapViewDelegate>	{
	IBOutlet MKMapView *gameMap;
and in interface builder i have the mkmapview gameMap's delegate as file's owner.

please end my frustration i just want these damn pins to be the image "1.png"

I am not a very good proof-reader. If there are ANY differences in the parameters, names or capitalization of the method declaration, it won't get called. One thing I did notice is that your method declares the annotation property as type (id), and the method signature in the docs is for (id <MKAnnotation>), which is a pointer to an anonymous object that implements the <MKAnnotation> protocol. I don't think parameter type mismatches prevent methods from getting called (unlike C++) but I would change it anyway. In fact, I would suggest going to the XCode docs on the mapView:viewForAnnotation: method and copy and pasting the method declaration from the docs directly into your code.

BTW, set the breakpoint in the debugger at the beginning of your viewDidLoad again, and check the type of the gameMap instance variable. If it is pointing to some other object, that would do it.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-06-2010, 09:14 PM   #6 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 22
Default

Quote:
Originally Posted by Duncan C View Post
I am not a very good proof-reader. If there are ANY differences in the parameters, names or capitalization of the method declaration, it won't get called. One thing I did notice is that your method declares the annotation property as type (id), and the method signature in the docs is for (id <MKAnnotation>), which is a pointer to an anonymous object that implements the <MKAnnotation> protocol. I don't think parameter type mismatches prevent methods from getting called (unlike C++) but I would change it anyway. In fact, I would suggest going to the XCode docs on the mapView:viewForAnnotation: method and copy and pasting the method declaration from the docs directly into your code.

BTW, set the breakpoint in the debugger at the beginning of your viewDidLoad again, and check the type of the gameMap instance variable. If it is pointing to some other object, that would do it.
I got it. Well my first issue is i shouldn't just be copying sensitive methods like that from the internet haha and my second issue was i was setting the delegate in the viewDidLoad method when I hadn't even instantiated it yet.

There is another view that loads the map when it is finally ready. after instantiation i then set the delegate to self and it worked. i hope google indexes this for others to follow.

i want the past 4 hours of my life back!

thanks again!!
meleader2 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
» Stats
Members: 158,884
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, karlam963
Powered by vBadvanced CMPS v3.1.0

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