Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

doanelinde

macrumors member
Original poster
Jul 24, 2009
35
0
When doing this tutorial (you can simply download the sample code), I tried to add two NSStrings in order to be able to dynamically change the title and subtitle of my pin annotations from a seperate class that calls the AddressAnnotation class.

This is the header code:

Code:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface AddressAnnotation : NSObject<MKAnnotation> {
	CLLocationCoordinate2D coordinate;
	
	NSString *mTitle;
	NSString *mSubTitle;
}

@end

First, why don't mTitle and mSubTitle need @property and @synthesize?

Second, is there anyway to access these two strings, I can't figure out how to change them, it won't work! I've tried things like
Code:
[AddressAnnotation setmTitle:@"blabla"];
but no cigar...

And then when I try to add my own NSStrings it throws an error for the @synthesize saying there is no property definition in the header file!?

Any help greatly appreciated!
 
To use a setter method you either have to write your own or use property/synthesize to create one for you. Since you seem to have done neither that's why setmTitle doesn't work.

To use @synthesize you have to have a corresponding @property
 
No no, I know that. The code above is taken directly from a tutorial, and if I try to add in @property and @synthesize, it won't let me. So I tried to add in other properties, including @property and @synthesize but it won't let me add anything else either, it just throws up an error in my implementation file by my @synthesize telling me there is no such property defined in my header..

The code above does work without the getters and setters though, it doesn't crash it just means I can't change the title or subtitle at runtime.
 
Although it seemed to work without the setters and getters (by work I mean compile, but still couldn't access properties) I tried my own setters and getts and no matter what I did the implementation file just couldn't seem to be able to see the property declaration in the header, it just kept saying it wasn't there.

So anyways, I created some new files and retyped all the code again (but with the property and synthesize I'd been trying to add the whole time), and I'm positive I didn't change anything, and the first time I did this the title worked but bizarrely not the subtitle... Did it again and it all worked.

This still puzzles me and makes no sense but I'm glad it's over with, twas causing me a lot of hassle!


It seems to be like that solution in Java(netbeans), where you're throwing up errors, cut the code out and compile, then paste it in again and compile and BAM, you're errors disappear!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.