Can't access annotation property of subclassed uibutton - editted

Posted by Tzur Gazit on Stack Overflow See other posts from Stack Overflow or by Tzur Gazit
Published on 2010-04-27T05:37:14Z Indexed on 2010/04/27 7:23 UTC
Read the original article Hit count: 287

Filed under:
|

Below is my original question. I kept investigating and found out that the type of the button I allocate is of type UIButton instead of the subclassed type CustomButton.

the capture below is the allocation of the button and connection to target. I break immediately after the allocation and check the button type (po rightButton at the debugger console). It's turned out tht the type is UIButton instead of CustomButton.

    CustomButton* rightButton = [CustomButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton addTarget:self
                    action:@selector(showDetails:)
          forControlEvents:UIControlEventTouchUpInside];

I have a mapView to which I add annotations. The pin's callout have a button (rightCalloutAccessoryView). In order to be able to display various information when the button is pushed, i've subclassed uibutton and added a class called "Annotation".

 @interface CustomButton : UIButton {

   NSIndexPath *indexPath;
   Annotation *mAnnotation;

  }

@property (nonatomic, retain) NSIndexPath *indexPath;
@property (nonatomic, copy) Annotation *mAnnotation;

- (id) setAnnotation2:(Annotation *)annotation;

@end

Here is "Annotation":

@interface Annotation : NSObject <MKAnnotation> {

CLLocationCoordinate2D coordinate;
NSString *mPhotoID;
NSString *mPhotoUrl;
NSString *mPhotoName;
NSString *mOwner;
NSString *mAddress;
}

@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *mPhotoID;
@property (nonatomic, copy) NSString *mPhotoUrl;
@property (nonatomic, copy) NSString *mPhotoName;
@property (nonatomic, copy) NSString *mOwner;
@property (nonatomic, copy) NSString *mAddress;

- (id) initWithCoordinates:(CLLocationCoordinate2D)coordinate;
- (id) setPhotoId:(NSString *)id url:(NSString *)url owner:(NSString *)owner     address:(NSString *)address andName:(NSString *)name;


@end

I want to set the annotation property of the uibutton at - (MKAnnotationView *)mapView:(MKMapView *)pMapView viewForAnnotation:(id )annotation, in order to refer to it at the button push handler (-(IBAction) showDetails:(id)sender).

The problem is that I can't set the annotation property of the button. I get the following message at run time:

2010-04-27 08:15:11.781 HotLocations[487:207] *** -[UIButton setMAnnotation:]:     unrecognized selector sent to instance 0x5063400
2010-04-27 08:15:11.781 HotLocations[487:207] *** Terminating app due to uncaught   exception 'NSInvalidArgumentException', reason: '*** -[UIButton setMAnnotation:]:   unrecognized selector sent to instance 0x5063400'
2010-04-27 08:15:11.781 HotLocations[487:207] Stack: (
32080987,
2472563977,
32462907,
32032374,
31884994,
55885,
30695992,
30679095,
30662137,
30514190,
30553882,
30481385,
30479684,
30496027,
30588515,
63333386,
31865536,
31861832,
40171029,
40171226,
2846639
)

I appreciate the help. Tzur.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c