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 03-22-2010, 08:42 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 98
veeplus is on a distinguished road
Default problem with map annotations (NSInvalidArgumentException)

i am trying to put annotations on my map view. i'm using the WeatherMap sample code from the Apple website. the difference between that code and mine is that my map view is a tab in a tab bar controller. my program is crashing when i click the map tab and i'm getting this error:

*** -[MKUserLocation high]: unrecognized selector sent to instance 0x506f260
2010-03-22 21:31:26.290 WhereAmI01[1218:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[MKUserLocation high]: unrecognized selector sent to instance 0x506f260'

the crash seems to be happening at this line in WeatherAnnotationView.m:
NSInteger high = [weatherItem.high integerValue];

here's the method it's in:
Code:
- (void)drawRect:(CGRect)rect
{
    WeatherItem *weatherItem = (WeatherItem *)self.annotation;
    if (weatherItem != nil)
    {
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetLineWidth(context, 1);
        
        // draw the gray pointed shape:
        CGMutablePathRef path = CGPathCreateMutable();
        CGPathMoveToPoint(path, NULL, 14.0, 0.0);
        CGPathAddLineToPoint(path, NULL, 0.0, 0.0); 
        CGPathAddLineToPoint(path, NULL, 55.0, 50.0); 
        CGContextAddPath(context, path);
        CGContextSetFillColorWithColor(context, [UIColor lightGrayColor].CGColor);
        CGContextSetStrokeColorWithColor(context, [UIColor grayColor].CGColor);
        CGContextDrawPath(context, kCGPathFillStroke);
        CGPathRelease(path);
        
        // draw the cyan rounded box
        path = CGPathCreateMutable();
        CGPathMoveToPoint(path, NULL, 15.0, 0.5);
        CGPathAddArcToPoint(path, NULL, 59.5, 00.5, 59.5, 5.0, 5.0);
        CGPathAddArcToPoint(path, NULL, 59.5, 69.5, 55.0, 69.5, 5.0);
        CGPathAddArcToPoint(path, NULL, 10.5, 69.5, 10.5, 64.0, 5.0);
        CGPathAddArcToPoint(path, NULL, 10.5, 00.5, 15.0, 0.5, 5.0);
        CGContextAddPath(context, path);
        CGContextSetFillColorWithColor(context, [UIColor cyanColor].CGColor);
        CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
        CGContextDrawPath(context, kCGPathFillStroke);
        CGPathRelease(path);
 
        NSInteger high = [weatherItem.high integerValue];
        NSInteger low = [weatherItem.low integerValue];

        // draw the temperature string and weather graphic
        NSString *temperature = [NSString stringWithFormat:@"%@\n%d / %d", weatherItem.place, high, low];
        [[UIColor blackColor] set];
        [temperature drawInRect:CGRectMake(15.0, 5.0, 50.0, 40.0) withFont:[UIFont systemFontOfSize:11.0]];
        NSString *imageName = nil;
        switch ([weatherItem.condition integerValue])
        {
            case Sunny:
                imageName = @"sunny.png";
                break;
            case PartlyCloudy:
                imageName = @"partly_cloudy.png";
                break;
            case Cloudy:
                imageName = @"cloudy.png";             
                break;
            default:
                imageName = @"partly_cloudy.png";
                break;
        }
        [[UIImage imageNamed:imageName] drawInRect:CGRectMake(12.5, 28.0, 45.0, 45.0)];
    }
}

what could be the issue?

thanks.
veeplus is offline   Reply With Quote
Old 03-27-2010, 04:37 PM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 98
veeplus is on a distinguished road
Default

can anyone help me with this? i'm really stuck.
veeplus is offline   Reply With Quote
Old 03-28-2010, 09:46 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 98
veeplus is on a distinguished road
Default

no one?
veeplus is offline   Reply With Quote
Old 03-28-2010, 10:27 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default Is that code in your annotation view?

Quote:
Originally Posted by veeplus View Post
i am trying to put annotations on my map view. i'm using the WeatherMap sample code from the Apple website. the difference between that code and mine is that my map view is a tab in a tab bar controller. my program is crashing when i click the map tab and i'm getting this error:

*** -[MKUserLocation high]: unrecognized selector sent to instance 0x506f260
2010-03-22 21:31:26.290 WhereAmI01[1218:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[MKUserLocation high]: unrecognized selector sent to instance 0x506f260'

the crash seems to be happening at this line in WeatherAnnotationView.m:
NSInteger high = [weatherItem.high integerValue];


what could be the issue?

thanks.
Is that code in your annotation view object? That isn't clear.

I am guessing that your "WeatherItem" is your annotation object?

It looks to me like the object that's returned at the top of the -drawRect method in the line:

WeatherItem *weatherItem = (WeatherItem *)self.annotation;

...is not really a WeatherItem.

It might even be the userLocation annotation object.

Add some checking code:

Code:
id theAnnotation = self.annotation;

if ([theAnnotation class] != [WeatherItem class])
{
   NSLog(@"annotation object is not a WeatherItem. class = %@", 
      [theAnnotation class]);
   return;
}

WeatherItem *weatherItem = (WeatherItem *) theAnnotation;

Last edited by Duncan C; 03-28-2010 at 10:28 PM. Reason: Syntax error
Duncan C is offline   Reply With Quote
Old 03-28-2010, 10:43 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 98
veeplus is on a distinguished road
Default

thanks for your response! you were right.. it is an MKUserLocation, not a WeatherItem. with your code, the program no longer crashes. i don't really understand what's going on though. i just integrated the code from the WeatherMap sample code into my own program. i didn't change any of the annotation stuff so how come it's behaving differently in my program vs in the sample?

i'm also confused by the fact that my console printed in this order:

2010-03-28 23:40:34.477 WhereAmI01[2603:207] made it to here
2010-03-28 23:40:34.478 WhereAmI01[2603:207] made it to here2
2010-03-28 23:40:34.480 WhereAmI01[2603:207] made it to here
2010-03-28 23:40:34.480 WhereAmI01[2603:207] made it to here2
2010-03-28 23:40:34.482 WhereAmI01[2603:207] made it to here
2010-03-28 23:40:34.483 WhereAmI01[2603:207] made it to here2
2010-03-28 23:40:34.483 WhereAmI01[2603:207] made it to here
2010-03-28 23:40:34.484 WhereAmI01[2603:207] made it to here2
2010-03-28 23:40:37.451 WhereAmI01[2603:207] annotation object is not a WeatherItem. class = MKUserLocation

when the code was:

Code:
- (void)drawRect:(CGRect)rect
{
	
	id theAnnotation = self.annotation;
	
	if ([theAnnotation class] != [WeatherItem class])
	{
		NSLog(@"annotation object is not a WeatherItem. class = %@", 
			  [theAnnotation class]);
		return;
	}
	
	WeatherItem *weatherItem = (WeatherItem *) theAnnotation;
	
    //WeatherItem *weatherItem = (WeatherItem *)self.annotation;
    if (weatherItem != nil)
    {
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetLineWidth(context, 1);
        
        // draw the gray pointed shape:
        CGMutablePathRef path = CGPathCreateMutable();
        CGPathMoveToPoint(path, NULL, 14.0, 0.0);
        CGPathAddLineToPoint(path, NULL, 0.0, 0.0); 
        CGPathAddLineToPoint(path, NULL, 55.0, 50.0); 
        CGContextAddPath(context, path);
        CGContextSetFillColorWithColor(context, [UIColor lightGrayColor].CGColor);
        CGContextSetStrokeColorWithColor(context, [UIColor grayColor].CGColor);
        CGContextDrawPath(context, kCGPathFillStroke);
        CGPathRelease(path);
        
        // draw the cyan rounded box
        path = CGPathCreateMutable();
        CGPathMoveToPoint(path, NULL, 15.0, 0.5);
        CGPathAddArcToPoint(path, NULL, 59.5, 00.5, 59.5, 5.0, 5.0);
        CGPathAddArcToPoint(path, NULL, 59.5, 69.5, 55.0, 69.5, 5.0);
        CGPathAddArcToPoint(path, NULL, 10.5, 69.5, 10.5, 64.0, 5.0);
        CGPathAddArcToPoint(path, NULL, 10.5, 00.5, 15.0, 0.5, 5.0);
        CGContextAddPath(context, path);
        CGContextSetFillColorWithColor(context, [UIColor cyanColor].CGColor);
        CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
        CGContextDrawPath(context, kCGPathFillStroke);
        CGPathRelease(path);
        
				NSLog(@"made it to here");
        NSInteger high = [weatherItem.high integerValue];
        NSInteger low = [weatherItem.low integerValue];
				NSLog(@"made it to here2");

        // draw the temperature string and weather graphic
        NSString *temperature = [NSString stringWithFormat:@"%@\n%d / %d", weatherItem.place, high, low];
        [[UIColor blackColor] set];
        [temperature drawInRect:CGRectMake(15.0, 5.0, 50.0, 40.0) withFont:[UIFont systemFontOfSize:11.0]];
        NSString *imageName = nil;
        switch ([weatherItem.condition integerValue])
        {
            case Sunny:
                imageName = @"sunny.png";
                break;
            case PartlyCloudy:
                imageName = @"partly_cloudy.png";
                break;
            case Cloudy:
                imageName = @"cloudy.png";             
                break;
            default:
                imageName = @"partly_cloudy.png";
                break;
        }
        [[UIImage imageNamed:imageName] drawInRect:CGRectMake(12.5, 28.0, 45.0, 45.0)];
    }
}
i guess i am just confused overall about this annotation stuff.
veeplus is offline   Reply With Quote
Old 01-26-2012, 10:57 PM   #6 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 2
sunlite is on a distinguished road
Default current address and POI

thanks Duncan C. I also meet the same problem with Veeplus and my problem is also solved with your advice.

But new problem appears.

I integrate the Apple's sample code "current Address" and " weather Map " together to achieve this: the customer first can find his current address and narrow down to a small range around his current address via this App,then some other POI around him with image annotations ( like in the weather map sample code) appear.

Before using your advice, I have to delete the following code ( otherwise it would be crash and same errors like Veeplus ) :
- (MKAnnotationView *)mapView: (MKMapView *)map viewForAnnotationid <MKAnnotation>)annotation
{
static NSString *AnnotationViewID = @"annotationViewID";

WeatherAnnotationView *annotationView =
(WeatherAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:Annota tionViewID];
if (annotationView == nil)
{
annotationView = [[[WeatherAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.annotation = annotation;
return annotationView;
}
--------------
I just leave the following pragma mark Map View Delegate method:
--------------
- (void)mapViewMKMapView *)map regionDidChangeAnimatedBOOL)animated
{
NSArray *weatherItems = [weatherServer weatherItemsForMapRegion:mapView.region maximumCount:4];
[mapView addAnnotations:weatherItems];
}
-------
I achieved this : the customer first can find his current address MARKED with BLUE PIN and narrow down to a small range around his current address via this App, then some other POI around him with just RED PIN appear.

After use your advice and use the deleted code above:
-----
- (MKAnnotationView *)mapViewMKMapView *)map viewForAnnotation: (id <MKAnnotation>)annotation
{static NSString *AnnotationViewID = @"annotationViewID";

WeatherAnnotationView *annotationView =
(WeatherAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:Annota tionViewID];
if (annotationView == nil)
{
annotationView = [[[WeatherAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.annotation = annotation;
return annotationView;
}
------------
the customers first can find his current address and narrow down to a small range around his current address via this App,then some other POI around him with with image annotations. But do not have a marked "BLUE PIN " pointing to his current address.

How can I get customer's current address MARKED with a "BLUE PIN ", at the same time, showing POI around him with image annotations.

thanks!

Last edited by sunlite; 01-26-2012 at 11:05 PM.
sunlite is offline   Reply With Quote
Old 01-27-2012, 07:57 PM   #7 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 2
sunlite is on a distinguished road
Default

my question closed when add a check right at the beginning to test whether MapKit is asking for the blue pin's annotation view. If it is, return nil,
sunlite 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: 350
11 members and 339 guests
akacaj, c2matrix, cgokey, esoteric, givensur, HemiMG, Mirotion22, mjnafjke, Pudding, SLIC, Techgirl-52
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,651
Threads: 94,115
Posts: 402,887
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Mirotion22
Powered by vBadvanced CMPS v3.1.0

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