0

そこで、選択した注釈の上に表示されるカスタム吹き出しを作成しました。すべてが希望どおりに機能します。唯一の問題は、同じタイプの別のピンをドロップした後、過去のすべてのピンに同じ情報が表示されることです。たとえば、コールアウト「マクドナルド」に表示されるピン ドロップがあり、ドロップされる次のピンに「スターバックス」が表示される場合があります。これで、以前にドロップしたすべてのピンに「スターバックス」が表示されます。

私は現在、注釈のサブタイトル プロパティに情報を保存しようとしており、それを書式設定された文字列を介してカスタム UIView のラベルに表示しようとしています...動作しますが、注釈の情報が変更されないようにする必要があります。私が見逃しているか、理解していない何かがあるに違いありません。どんな助けでも大歓迎です。

関連すると思われるすべてのコードを以下に掲載しました。ありがとうございました!

カスタム Callout.h

#import <UIKit/UIKit.h>

@interface PinView : UIView
{
    UIView *view;
    UILabel *theValueLabel;
}

@property (nonatomic, retain) IBOutlet UIView *view;
@property (nonatomic, retain) IBOutlet UILabel *theValueLabel;

@end

カスタム Callout.m

#import "PinView.h"

@implementation PinView
@synthesize theValueLabel;
@synthesize view;



- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        UIView *nib = [[[UINib nibWithNibName:@"customView" bundle:nil] instantiateWithOwner:self options:nil] objectAtIndex:0];
        [self addSubview:nib];
    }
    return self;
}


-(id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        if (self.subviews.count == 0) {
            UIView *nib = [[[UINib nibWithNibName:@"customView" bundle:nil] instantiateWithOwner:self options:nil] objectAtIndex:0];
            [self addSubview:nib];
        }
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setup];
}

- (void)setup {
    self.theValueLabel.text = @"foo";
}

私のメインView Controller.mで

@interface BreadTrailViewController ()<CLLocationManagerDelegate, MKMapViewDelegate, MFMailComposeViewControllerDelegate>
{
    PinView *aView

    MKPointAnnotation *Pin1;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation *location = [locations lastObject];

    if (location != nil)
    {
         Pin1 = [[MKPointAnnotation alloc] init];
         Pin1.title = @"Venue";
         Pin1.subtitle = [NSString stringWithFormat:@"Venue Name: %@\n%f,%f\nAddress: %@",revGeocodeVenue, lat, lng, revGeocodeAddress];
         Pin1.coordinate = location.coordinate;
         [self.mapView addAnnotation:Pin1];
    }
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    // If it's the user location, just return nil.
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    // Handle any custom annotations.
    if ([annotation isKindOfClass:[MKPointAnnotation class]])
    {
        MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];

        if (!pinView)
        {
            pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];

            pinView.canShowCallout = NO;

        } else {

            pinView.annotation = annotation;
        }

        if ([[annotation title] containsString:@"Venue"])
        {
            pinView.pinTintColor = [UIColor greenColor];
        }

        return pinView;

    }
    return nil;

}

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    aView = [[PinView alloc] initWithFrame:CGRectMake( 0, 0, 300, 350)];

    aView.layer.cornerRadius = 20;
    aView.layer.masksToBounds = YES;
    aView.center = CGPointMake(view.bounds.size.width*0.5f, -aView.bounds.size.height*0.35f);

    //Using the Pin's subtitle to store the data string and display on PinView
    if ([[view.annotation title] containsString:@"Venue"])
    {
        aView.theValueLabel.text = Pin1.subtitle;
    }

    [view addSubview:aView];
}

-(void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
{
    [aView removeFromSuperview];
}
4

1 に答える 1

0

問題が見つかりました!使用すべきものが view.annotation.subtitle であるときに、Pin1.subtitle を使用していました。現在、すべてが完全に機能しています。これが他の誰かに役立つことを願っています!

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    aView = [[PinView alloc] initWithFrame:CGRectMake( 0, 0, 300, 350)];

    aView.layer.cornerRadius = 20;
    aView.layer.masksToBounds = YES;
    aView.center = CGPointMake(view.bounds.size.width*0.5f, -aView.bounds.size.height*0.35f);

    //Using the Pin's subtitle to store the data string and display on PinView
    if ([[view.annotation title] containsString:@"Venue"])
    {
        aView.theValueLabel.text = view.annotation.subtitle;
    }

    [view addSubview:aView];
}
于 2015-11-23T17:12:33.067 に答える