Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在mkMapView ios中单击按钮发送对象_Ios_Uibutton_Mkmapview_Mapkit_Sender - Fatal编程技术网

在mkMapView ios中单击按钮发送对象

在mkMapView ios中单击按钮发送对象,ios,uibutton,mkmapview,mapkit,sender,Ios,Uibutton,Mkmapview,Mapkit,Sender,在我的Mapview中,我有一个sum注释,注释中有一个按钮,该按钮将我发送到另一个视图,以获取有关此注释的更多详细信息 我的代码是 myAnnotation *myAnn = (myAnnotation *)annotation; UIButton *discloseButton = [UIButton buttonWithType: UIButtonTypeDetailDisclosure]; [discloseButton addTarget: self action: @

在我的Mapview中,我有一个sum注释,注释中有一个按钮,该按钮将我发送到另一个视图,以获取有关此注释的更多详细信息

我的代码是

myAnnotation *myAnn = (myAnnotation *)annotation;
    UIButton *discloseButton = [UIButton buttonWithType: UIButtonTypeDetailDisclosure];
    [discloseButton addTarget: self action: @selector(showInfo:) forControlEvents: UIControlEventTouchUpInside];
    annotationView.rightCalloutAccessoryView = discloseButton;
    UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:myAnn.image]];
    UIImage *pinImage = [UIImage imageNamed:@"pointer.png"];
    [annotationView setImage:pinImage];
    annotationView.leftCalloutAccessoryView = leftIconView;
    return annotationView;


如何通过单击填充我的表detailviewcontroller.DetailModal的按钮发送对象注释?

使用mapview的委托方法:
-(void)地图视图:(MKMapView*)地图视图注释视图:(MKAnnotationView*)视图调用访问控制点击:(UIControl*)控制

而不是您自己分配给按钮的操作

功能示例代码:

#import "ViewController.h"
#import <MapKit/MapKit.h>

@interface ViewController () <MKMapViewDelegate>
@end

@interface Test : NSObject<MKAnnotation>
@property MKMapView *mapView;
@end

@implementation Test

-(NSString *)title {
    return @"test";
}

- (CLLocationCoordinate2D)coordinate {
    return self.mapView.centerCoordinate;
}

@end
@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    MKMapView *mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
    mapView.delegate = self;
    [self.view addSubview:mapView];

    Test *test = [[Test alloc] init];
    test.mapView = mapView;
    [mapView addAnnotation:test]; //just as a test
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"test"];
    UIButton *discloseButton = [UIButton buttonWithType: UIButtonTypeDetailDisclosure];
    discloseButton.tag = 1;
    annotationView.canShowCallout = YES;
    annotationView.rightCalloutAccessoryView = discloseButton;
    return annotationView;
}

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    NSLog(@"annotationView %@", view);
    NSLog(@"tag  of click %d", control.tag);
    NSLog(@"annotation %@", view.annotation);
}
@end
#导入“ViewController.h”
#进口
@界面视图控制器()
@结束
@接口测试:NSObject
@属性MKMapView*mapView;
@结束
@实施测试
-(NSString*)标题{
返回@“测试”;
}
-(CLLocationCoordinate2D)坐标{
返回self.mapView.centerCoordinate;
}
@结束
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
MKMapView*mapView=[[MKMapView alloc]initWithFrame:self.view.bounds];
mapView.delegate=self;
[self.view addSubview:mapView];
Test*Test=[[Test alloc]init];
test.mapView=mapView;
[mapView addAnnotation:test];//就像测试一样
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释{
MKAnnotationView*annotationView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:@“test”];
UIButton*DispositionButton=[UIButton Button类型:UIButtonTypedTailDisposition];
dispositeButton.tag=1;
annotationView.canShowCallout=是;
annotationView.rightCalloutAccessoryView=披露按钮;
返回注释视图;
}
-(无效)地图视图:(MKMapView*)地图视图注释视图:(MKAnnotationView*)视图调用访问控制点击:(UIControl*)控制{
NSLog(@“annotationView%@”,视图);
NSLog(@“单击%d的标记”,control.tag);
NSLog(@“annotation%@”,view.annotation);
}
@结束

您可以将所有数据发送到格式化字符串,并在
prepareforsgue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"aa"])
    {
        UIButton *button = (UIButton *)sender;
        NSArray* infos = [button.accessibilityHint componentsSeparatedByString: @"::"];
        if ([infos count] > 1)
        {
            tit = [infos objectAtIndex:0];
            description = [infos objectAtIndex:1];
            Latitude = [infos objectAtIndex:2];
            longitude = [infos objectAtIndex:3];
            image = [infos objectAtIndex:4];
            type = [infos objectAtIndex:5];
            ville = [infos objectAtIndex:6];
            point = [infos objectAtIndex:7];
            nombreDeVisite = [infos objectAtIndex:8];
            nbVTotal = [infos objectAtIndex:9];
            idMission = [infos objectAtIndex:10];
        }
        DetailViewController *detailviewcontroller = [segue destinationViewController];
        detailviewcontroller.DetailModal = @[tit,description,Latitude,longitude,image,type,ville,point,nombreDeVisite,nbVTotal,idMission];
    }
}
代码是这样的

myAnnotation *myAnn = (myAnnotation *)annotation;
UIButton *discloseButton = [UIButton buttonWithType: UIButtonTypeDetailDisclosure];
[discloseButton addTarget: self action: @selector(showInfo:) forControlEvents: UIControlEventTouchUpInside];

NSString *detail = [NSString stringWithFormat:@"%@::%@::%@::%@::%@::%@::%@::%@::%@::%@::%@"
        ,myAnn.title,myAnn.description,myAnn.Latitude,myAnn.longitude,myAnn.image,myAnn.type,myAnn.ville,myAnn.point,myAnn.nombreDeVisite,myAnn.nbVTotal,myAnn.idMission];


discloseButton.accessibilityHint = detail;
annotationView.rightCalloutAccessoryView = discloseButton;
在您的函数中
prepareForSegue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"aa"])
    {
        UIButton *button = (UIButton *)sender;
        NSArray* infos = [button.accessibilityHint componentsSeparatedByString: @"::"];
        if ([infos count] > 1)
        {
            tit = [infos objectAtIndex:0];
            description = [infos objectAtIndex:1];
            Latitude = [infos objectAtIndex:2];
            longitude = [infos objectAtIndex:3];
            image = [infos objectAtIndex:4];
            type = [infos objectAtIndex:5];
            ville = [infos objectAtIndex:6];
            point = [infos objectAtIndex:7];
            nombreDeVisite = [infos objectAtIndex:8];
            nbVTotal = [infos objectAtIndex:9];
            idMission = [infos objectAtIndex:10];
        }
        DetailViewController *detailviewcontroller = [segue destinationViewController];
        detailviewcontroller.DetailModal = @[tit,description,Latitude,longitude,image,type,ville,point,nombreDeVisite,nbVTotal,idMission];
    }
}

这是一个极其粗糙和脆弱的解决方案。分隔的详细信息字符串是完全不必要的,而且非常不面向对象。它完全违背了OP定义的自定义注释类对象
myAnnotation
的优点。有关更好的方法,请参阅和。