Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button on Custom info Window not Receiving Action in ios

I am using Google Maps in iOS Application and have implemented a custom info window for showing title of a marker.
Now, I added a button on that custom info window but my problem is that the button action method does not get called.

CustomInfoWindow.h

#import <UIKit/UIKit.h>

@interface CustomInfoWindow : UIView
@property (nonatomic,weak) IBOutlet UILabel *addressLabel;
@property(nonatomic) IBOutlet UIButton *button;
@end

and in infoWindow.xib, I have added

  • UILabel called addressLabel
  • UIButton called button

ViewController.h

#import "CustomInfoWindow.h"

@interface viewController : UIViewController<GMSMapViewDelegate>
{
  GMSMapView *mapView;
}
@end

ViewController.m

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
    NSLog(@"Mrker Tapped");

    CustomInfoWindow *infoWindow = [[[NSBundle mainBundle]loadNibNamed:@"infoWindow"
                                                                 owner:self
                                                               options:nil] objectAtIndex:0];
    infoWindow.addressLabel.text = marker.title;    

    [infoWindow.button addTarget:self action:@selector(ButtonPressed) 
                            forControlEvents:UIControlEventTouchUpInside];
    return infoWindow;
}

-(void)ButtonPressed
{
    NSLog(@"Button Pressed");
}

Basically... ButtonPressed method does not fire.

like image 352
Suresh Peddisetti Avatar asked Apr 21 '14 12:04

Suresh Peddisetti


1 Answers

I haven't used Google Maps SDK but after following a few links, it seems what you're trying to accomplish may not be easy.

ref: https://developers.google.com/maps/documentation/android/infowindows
PS: This maybe Android documentation but it seems it holds true for iOS as well.

To quote:

Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (for example, after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.

You could instead implement GMSMapViewDelegate's -didTapInfoWindowOfMarker: delegate method to check if the infowindow was tapped.
(the drawback is that the entire infowindow becomes one button)


Other links:

similar question 1
similar question 2

like image 65
staticVoidMan Avatar answered Oct 22 '22 15:10

staticVoidMan