pressing按钮后,更改PIN的颜色在地图上的另一个屏幕上 [英] Change color of pin on map after pressing button on another screen

查看:260
本文介绍了pressing按钮后,更改PIN的颜色在地图上的另一个屏幕上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到一种方法来改变时,地图是通过从其他画面按下一个按钮加载的脚色。

I need to find a way to change the pin color when the map is loaded by pushing a button from another screen.

例如,原来的引脚都红了,但是当我去到一个页面并推动地图按钮,它必须使我的地图视图和所在位置的坐标必须标有绿色引脚。

For example, the original pins are all red, but when I go to a page and push the map button, it has to lead me to the map view and the coordinates of that location have to be marked with a green pin.

我已经在地图设置,使引脚的设置都红了。

I already have the map set up and the setup of making the pins all red.

任何帮助是AP preciated。

Any help is appreciated.

所以,只要回顾一下:
网页地图用红别针 - >点击针,单击批注(另一种视图中打开) - >里面查看,有一个按钮,点击按钮(如@更改PIN色。) - >地图绿色页脚打开。 (看看上面有图片的例子。)

So, just a recap: Page with map with red pin --> click pin, click annotation (another view opens) --> inside view, there is a button (eg. @"change pin color"), click button --> page with map with green pin opens. (Look at the example above with pictures.)

推荐答案

为什么你不只是声明了一个新的构造函数来设置你所选择的颜色?

Why don't you just declare a new constructor to set the colour of your choice?

// ViewControllerB .h file
@interface ViewControllerB
{
    UIColor *pinColor;
}

-(id)initWithPinColor:(UIColor *)chosenPinColor;

...

// ViewControllerB .m file
-(id)initWithPinColor:(UIColor *)chosenPinColor
{
    self = [super init];

    if(self)
    {
        pinColor = chosenPinColor;
    }

    return self;
}

...

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    if([annotation isKindOfClass:[MKUserLocation class]])
    {
        return nil;
    }

    static NSString *annotationViewID = @"annotationViewID";

    MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationViewID];

    if(!annotationView)
    {
        annotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationViewID] autorelease];
    }

    // this will use the pinColor stored in the constructor
    annotationView.pinColor = pinColor;        
    annotationView.canShowCallout = YES;
    annotationView.animatesDrop = YES;

    annotationView.annotation = annotation;

    return annotationView;
}

然后,你可以简单地做这ViewControllerA:

Then you can simply do this in ViewControllerA:

// ViewControllerA .m file
#import "ViewControllerB.h"

...

-(void)showMapWithPinColor:(id)sender
{
    ViewControllerB *vc = [[ViewControllerB alloc] initWithPinColor:[UIColor green]];

    [self.navigationController pushViewController:vc animated:YES];
}

这篇关于pressing按钮后,更改PIN的颜色在地图上的另一个屏幕上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆