当用户点击mapview中的图钉时,调用另一个视图 [英] Call another view when user taps on pin in mapview

查看:65
本文介绍了当用户点击mapview中的图钉时,调用另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带有多重注释的地图,我希望用户点击图钉以调用另一个视图.

I have Map with multiply annotations and I want hen user taps on pin to call another view.

我正在使用情节提要.

使用.xib就是这样.

With .xib this would be like this.

...
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
...
[rightButton addTarget:self
                    action:@selector(showDetails:)
          forControlEvents:UIControlEventTouchUpInside];
}

-(void)showDetails:(UIButton*)sender {

     OfferDetailViewController *detail = [[OfferDetailViewController alloc] init];

     detail.context = context;

     Offers *offer = [arr objectAtIndex:indexPath.row];

     //detail.offer = offer;

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

...

推荐答案

您可以在视图之间创建Segue,并在StoryBoard中为其指定标识符.然后执行"performSegueWithIdentifier"来触发它.因此,在用户点击的方法中,如果您的Segue的标识符为"FrameSegue",则调用"performSegueWithIdentifier"之类的

You can create a Segue between the views and give it an identifier in StoryBoard. Then execute "performSegueWithIdentifier" to trigger it. So in your method which is called by the user tapping you call the "performSegueWithIdentifier" something like this if your Segue has an identifier of "FrameSegue"

[self performSegueWithIdentifier:@"FrameSegue" sender:sender];

如果需要先进行任何设置以将数据传递到另一个视图,则可以在"prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender"中设置转换.

You can setup the transition in "prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender" if you need do any setup first to pass data to the other view.

我希望能帮上忙.

在下面回答您的评论:-

Answer to your comment below :-

如果您将Segue标识为"FrameSegue",并且想要将字符串从视图"MyFirstView"传递到第二个视图"MySecondView",并将其存储在第二个视图的myData中.

If you have a Segue Identified as "FrameSegue" and you want to pass a string from the view "MyFirstView" to the second view called "MySecondView" and store it in myData in the second view.

尝试一下:

在MyFirstView.m

In MyFirstView.m

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    if ([segue.identifier isEqualToString:@"FrameSegue"]) {

        MySecondView *secondView = [segue destinationViewController];
        [secondView setMyData:myString];
    }
}

- (IBAction)tappedThing:(id)sender {

    NSString *myString = @"A String";

    [self performSegueWithIdentifier:@"FrameSegue" sender:sender];

}

这篇关于当用户点击mapview中的图钉时,调用另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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