Mapkit: won't let me assign additional properties

Discussion in 'iOS Programming' started by doanelinde, Jul 24, 2009.

  1. doanelinde macrumors member

    Joined:
    Jul 24, 2009
    #1
    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!
     
  2. Troglodyte macrumors member

    Joined:
    Jul 2, 2009
    #2
    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
     
  3. doanelinde thread starter macrumors member

    Joined:
    Jul 24, 2009
    #3
    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.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Have you defined a setmTitle: method? If not, you'll need to. If so, can we see the code for it?
     
  5. doanelinde thread starter macrumors member

    Joined:
    Jul 24, 2009
    #5
    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!
     

Share This Page